#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;
    int aa = min(totx, toty), bb = max(totx, toty);
    for (int i = aa; i >= 1; --i)
        for (int j = 1; j <= bb; ++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;
}