#include<bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
const int M = 1000000 + 5;
int d[M], step[M];
bool vis[M];
int main(){
int T;
cin>> T;
while(T--){
memset(vis, 0, sizeof(vis));
memset(d, 0, sizeof(d));
int head, tail;
int x, y;
cin>> x >> y;
head = 0;
tail = 0;
d[head] = x;
step[x] = 0;
vis[x] = 1;
if (d[head] == y){
cout<< step[d[head]] << endl;
continue;
}
while (head <= tail){
int u = d[head];
int su = step[u];
int v;
if (vis[v] == 0 && v < 2 * y) {
d[++tail] = v;
vis[v] = 1;
step[v] = step[u] + 1;
if (v == y) {
cout << step[v] << endl;
break;
}
}
v = u + 1;
if (vis[v] == 0 && v <= y) {
d[++tail] = v;
vis[v] = 1;
step[v] = step[u] + 1;
if (v == y) {
cout << step[v] << endl;
break;
}
}
v = u - 1;
if (vis[v] == 0 && v >= 0) {
d[++tail] = v;
vis[v] = 1;
step[v] = step[u] + 1;
if (v == y) {
cout << step[v] << endl;
break;
}
}
head++;
}
}
return 0;
}
0分