OIG XIV - spa

// https://szkopul.edu.pl/problemset/problem/OBf723EhSg5KedPQJDBJNHjX/site/?key=statement
// OIJ XIV próbne zawody 2 stopnia

#include <iostream>

long long pow2[] = {0,
                    2ll,
                    4ll,
                    8ll,
                    16ll,
                    32ll,
                    64ll,
                    128ll,
                    256ll,
                    512ll,
                    1024ll,
                    2048ll,
                    4096ll,
                    8192ll,
                    16384ll,
                    32768ll,
                    65536ll,
                    131072ll,
                    262144ll,
                    524288ll,
                    1048576ll,
                    2097152ll,
                    4194304ll,
                    8388608ll,
                    16777216ll,
                    33554432ll,
                    67108864ll,
                    134217728ll,
                    268435456ll,
                    536870912ll,
                    1073741824ll,
                    2147483648ll,
                    4294967296ll,
                    8589934592ll,
                    17179869184ll,
                    34359738368ll,
                    68719476736ll,
                    137438953472ll,
                    274877906944ll,
                    549755813888ll,
                    1099511627776ll,
                    2199023255552ll,
                    4398046511104ll,
                    8796093022208ll,
                    17592186044416ll,
                    35184372088832ll,
                    70368744177664ll,
                    140737488355328ll,
                    281474976710656ll,
                    562949953421312ll,
                    1125899906842624ll,
                    2251799813685248ll,
                    4503599627370496ll,
                    9007199254740992ll,
                    18014398509481984ll,
                    36028797018963968ll,
                    72057594037927936ll,
                    144115188075855872ll,
                    288230376151711744ll,
                    576460752303423488ll,
                    1152921504606846976ll};

int depth(long long x) {
    int i = 0;

    while (pow2[i] <= x) {
        i++;
    }

    return i;
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);

    int q;
    std::cin >> q;

    for (; q > 0; q--) {
        long long a, b;
        std::cin >> a >> b;

        int depth_a = depth(a);
        int depth_b = depth(b);

        if (depth_a > depth_b) {
            std::swap(a, b);
            std::swap(depth_a, depth_b);
        }

        int temp_depth = depth_b;

        while (temp_depth > depth_a) {
            b /= 2;
            temp_depth--;
        }

        while (a != b) {
            a /= 2;
            b /= 2;
        }

        int res = depth(a);

        int ans = depth_a + depth_b - 2 * res;

        std::cout << ans << '\n';
    }

    return 0;
}