#include <bits/stdc++.h>
using namespace std;
int x,y,a[3],t;
bool used[10000010];
int mi=INT_MAX;
struct dui{
int x,step;
}b[1000001];
int f(int x){
int head=0,tail=1,step=0;
b[1].x=x;b[1].step=0;
while(head<tail){
head++;
int n1=b[head].x,n2=b[head].step;
for(int i=0;i<3;i++){
int nx=n1+a[i],ns=n2+1;
if(nx>0&&used[nx]==0){
used[nx]=1;
tail++;
b[tail].x=nx;
b[tail].step=ns;
}
if(nx==y)
return ns;
}
}
}
int main(){
cin>>t;
a[0]=1;
a[1]=-1;
while(t--){
cin>>x>>y;
a[2]=x;
cout<<f(x);
}
return 0;
}