#include<bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout)
using namespace std;
int n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x,y,ans=0;
scanf("%d%d",&x,&y);
int depx=log2(x)+1,depy=log2(y)+1;
if(depx<depy) swap(x,y),swap(depx,depy);
// printf("x:%d y:%d\n",x,y);
for(int j=depy;j<depx;j++)
{
x/=2,ans++;
// printf("x:%d y:%d\n",x,y);
}
for(int j=log2(y);j>=1;j--)
{
if(x==y) break;
x/=2;
y/=2;
ans+=2;
// printf("x:%d y:%d\n",x,y);
}
printf("%d\n",ans);
}
return 0;
}