#include<bits/stdc++.h>
using namespace std;
queue<int> q;
int h[4]= {0,1,-1,0};
int b[12000000];
int bs[12000000];
int main() {
int T;
cin>>T;
while(T--) {
int n,m;
cin>>n>>m;
q.push(n);
if(n==m) {
cout<<0;
return 0;
}
while(!q.empty()) {
int x=q.front();
q.pop();
h[3]=x;
for(int i=1; i<=3; i++) {
if(b[x+h[i]]==0&&x+h[i]>=0&&x+h[i]<=200002) {
b[x+h[i]]=1;
bs[x+h[i]]=bs[x]+1;
q.push(x+h[i]);
if(x+h[i]==m) {
cout<<bs[x+h[i]]<<endl;
}
}
}
}
}
return 0;
}