Help me in solving STRFIRSTCHAR problem

My issue

if the first character is not equal then the two strings can never be equal .Therefore the answer for that case will be -1.
If both the strings are equal then simply we will print 0.
3rd Case: first character of both string is equal
In this minimum answer possible is either 1 or 2.
2 when we will take whole string as substring and print the first character in replacement of whole string.
‘1’ when all the characters of the smaller string is equal to other string .
ex-‘abcdfr’ and ‘abc’ Here we will replace cdfr with c.

My code

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        ll n,m;
        cin>>n>>m;
        string s;
        cin>>s;
        string t;
        cin>>t;
        ll x=0;
        if(s==t)
        cout<<"0"<<endl;
        else if(s[0]!=t[0])
        cout<<"-1"<<endl;
        else {
            for(int j=0;j<min(n,m);j++){
                if(s[j]==t[j])
                x++;
            }
            if(x==min(n,m))
            cout<<"1"<<endl;
        
            else 
            cout<<"2"<<endl;
        }
        
    }
	// your code goes here

}

Problem Link: Replace With First Practice Coding Problem