BINSHFFL : Codechef giving WA

enter code here
#include
using namespace std;

int countDigits(long long a){
int count=0;
while(a){
a=(a&(a-1));
count++;
}
return count;

}

int main(){
ios_base::sync_with_stdio(false);

int T;
cin>>T;
while(T--){
    long long A,B;
    cin>>A>>B;
    int ans;
    if(B==0){
        ans=-1;
        
    }
    else if(B==1 ){
        if(A==0)
        ans=1;
        
        else{
            ans=-1;
            
        }
    }
   else if(A==B){
        ans=0;
     
    }
    else{
        int digitsA=countDigits(A);
        int digitsB=countDigits(B-1);
        //cout<<"Digit A:"<<digitsA;
        //cout<<"Digit b:"<<digitsB;
        //cout<<endl;
    
        if(digitsB<digitsA)
        ans=2;
        else
        ans=digitsB-digitsA+1;
    
    }
    cout<<ans<<'\n';
}

}

Please look into solution.
I am getting WA.
Unable to resolve error

When both A and B are 0 or 1, the output should be 0 but your code gives output -1. Put the

<i>if(A==B){ans=0;}</i>

statement as the first

if statement

in your code and it will work correctly.

@rounak217 can you give me any test case where my test case failed. I am unable to submit my code.
here is my code. https://www.codechef.com/viewsolution/19040604
Please check it!