#include<bits/stdc++.h>
using namespace std;
int n;
inline const void read(int &a)
{
a=0;
char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c<='9'&&c>='0')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
}
int work(int x,int y)
{
int ans=0,k1[40],k2[40];
memset(k1,0,sizeof(k1));
memset(k2,0,sizeof(k2));
while(x)
{
k1[++k1[0]]=x%2;
x/=2;
}
while(y)
{
k2[++k2[0]]=y%2;
y/=2;
}
if(k1[0]==k2[0]) ans=0;
else if(k1[0]>k2[0])
ans=k1[0]-k2[0];
else ans=k2[0]-k1[0];
int k3=k1[0],k4=k2[0],k=min(k1[0],k2[0]),t=0;
while(k3&&k4)
{
if(k1[k3]==k2[k4])
{
k3--;
k4--;
t++;
}
else break;
}
return ans+(k-t)*2;
}
int main()
{
//freopen("city.in.txt","r",stdin);
//freopen("city.out.txt","w",stdout);
int x1,x2;
read(n);
for(int i=1;i<=n;i++)
{
read(x1);
read(x2);
if(x1==x2)
cout<<0<<endl;
else
{
int ans=work(x1,x2);
cout<<ans<<endl;
}
}
return 0;
}