#include <bits/stdc++.h>
#define int long long
using namespace std;
int koro(int A, int B) {
queue<pair<int, int>> q;
q.push({A, 0});
while (!q.empty()) {
pair<int, int> front = q.front();
q.pop();
int num = front.first;
int dorkar = front.second;
if (num == B)
return dorkar;
if (num * 2 <= B)
q.push({num * 2, dorkar + 1});
if (num + 1 <= B)
q.push({num + 1, dorkar + 1});
}
return LONG_LONG_MAX;
}
int32_t main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int T;
cin >> T;
while (T--) {
int A, B;
cin >> A >> B;
cout << koro(A, B) << endl;
}
return 0;
}