#include <bits/stdc++.h>
using namespace std;
int n, a, b, fa[10009], fb[10009];
int LCA(int x, int y) {
memset(fa, 0, sizeof(fa));
memset(fb, 0, sizeof(fb));
if (x == y) return 0;
int totx = 0, toty = 0, an, dep = 0;
while (x) {
fa[++totx] = x;
x /= 2;
}
while (y) {
fb[++toty] = y;
y /= 2;
}
if (x == 1 || y == 1) return max(totx, toty) - 1;
for (int i = totx; i >= 1; --i)
for (int j = 1; j <= toty; ++j)
if (fa[i] == fb[j]) {
an = fa[i];
break;
}
while (an) {
an /= 2;
dep++;
}
return totx + toty - 2 - 2 * (dep - 1);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a, &b);
printf("%d\n", LCA(a, b));
}
return 0;
}