#include<bits/stdc++.h>
using namespace std;
queue<int> q;
int dis[200005];
int n,k;
void bfs(){
q.push(n);
dis[n]=0;
while(!q.empty()){
int p=q.front();
q.pop();
if(p==k){
return ;
}
p++;
if(p>=0&&p<=200000&&dis[p]==-1){
dis[p]=dis[p-1]+1;
q.push(p);
}
p-=2;
if(p>=0&&p<=200000&&dis[p]==-1){
dis[p]=dis[p+1]+1;
q.push(p);
}
p++;
p*=2;
if(p>=0&&p<=200000&&dis[p]==-1){
dis[p]=dis[p/2]+1;
q.push(p);
}
p/=2;
}
}
int main(){
int t;
cin>>t;
while(t--){
scanf("%d%d",&n,&k);
memset(dis,-1,sizeof(dis));
bfs();
printf("%d\n",dis[k]);
}
return 0;
}
为什么错了?