#include <bits/stdc++.h>
int deep = 1, dep[33];
struct fastIn
{
template<typename T>
inline fastIn& operator>>(T &x)
{
x = 0; bool f = 1; register char c = getchar();
for(; !std::isdigit(c); c = getchar()) f ^= c == '-';
for(; std::isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x = f ? x : -x; return *this;
}
} io;
inline int lowerBound(int x)
{
int l = 1, r = 31;
while(l < r)
{
int mid = (l + r) >> 1;
if(dep[mid] >= x) r = mid;
else l = mid + 1;
}
if(dep[l] == x) return l;
return l - 1;
}
inline int LCA(int x, int y)
{
int dx = lowerBound(x), dy = lowerBound(y);
if(dx < dy) std::swap(x, y), std::swap(dx, dy);
for(int i = 1; i + dy <= dx; ++i) x >>= 1;
if(x == y) return dx - dy;
int cnt = 0;
for(; x != y; ++cnt) x >>= 1, y >>= 1;
return (cnt << 1) + (dx - dy);
}
signed main()
{
int n; io >> n;
for(int i = 1; i <= 31; ++i) dep[i] = deep, deep <<= 1;
for(int i = 1; i <= n; ++i)
{
int x, y; io >> x >> y;
printf("%d\n", LCA(x, y));
}
return 0;
}