#include using namespace std; const int MaxN = (int)1e5 + 10; const int MOD = (int)1e9 + 7; const int INF = 1e9; const int MAX_STEP=9; int dp[MAX_STEP][1028][1028]; int bits(int x) { int res = 0; while (x > 0) { res += x & 1; x /= 2; } return res; } int calc(int step, long long a, long long b) { if (max(a, b) >= 1024 || step>=MAX_STEP) { return INF; } if (a == b) { return 0; } if (dp[step][a][b] != -1) { return dp[step][a][b]; } dp[step][a][b] = 1e+9; for (int mask = 0; mask < 1 << 8; ++mask) { if (bits(mask) == bits(a) && mask + 1 < 256) { dp[step][a][b] = min(dp[step][a][b], 1 + calc(step+1, mask + 1, b)); } } return dp[step][a][b]; } void solve() { long long a, b; scanf("%lld%lld", &a, &b); assert (0 <= a && a <= 1e18); assert (0 <= b && b <= 1e18); if (a == b) { printf("0\n"); return; } if (a == 0 && b == 1) { printf("1\n"); return; } if (b <= 1) { printf("-1\n"); return; } cout << (calc(0, a, b) == INF ? -1 : calc(0, a, b)) << "\n"; } int main() { // freopen("input.txt", "r", stdin); // ios::sync_with_stdio(false); cin.tie(NULL); memset(dp, -1, sizeof(dp)); int t; scanf("%d", &t); assert (1 <= t && t <= 1e5); while (t --> 0) { solve(); } return 0; }