#include<bits/stdc++.h>
using namespace std;
int x,y;
bool nn[100005];
struct dian
{
int i,j;
};
int bfs()
{
queue<dian>dl;
dian now,nex;
now.i=x,now.j=0;
nn[x]=1;
dl.push(now);
for(int i=1;;i++)
{
if(dl.empty())
{
break;
}
now=dl.front();
dl.pop();
if(now.i==y)
{
return now.j;
}
nex.j=now.j+1;
if(now.i+1<=y&&!nn[now.i+1])
{
nex.i=now.i+1;
nn[nex.i]=1;
dl.push(nex);
}
if(now.i-1>=x&&!nn[now.i-1])
{
nex.i=now.i-1;
nn[nex.i]=1;
dl.push(nex);
}
if(now.i*2<=y&&!nn[now.i*2])
{
nex.i=now.i*2;
nn[nex.i]=1;
dl.push(nex);
}
}
}
int main()
{
int T;
cin>>T;
for(int t=1;t<=T;t++)
{
memset(nn,false,sizeof(nn));
cin>>x>>y;
cout<<bfs()<<'\n';
}
return 0;
}