#include<iostream>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
int dp[1010][1010];
int pow2[12] = {1};
using namespace std;
int f(int k, int n) {
if (k == 0) return 0;
if (n == 1) return k;
if (dp[k][n] > 0) return dp[k][n];
for (int i = 0; i < 12; i++)
if (k < pow2[i] && n > i)
return dp[k][n] = i;
int ans = k + 1;
for (int i = 1; i <= k; i++) {
ans = min(ans, max(f(i-1, n-1), f(k-i, n)) + 1);
}
return dp[k][n] = ans;
}
int main() {
for (int i = 1; i < 12; i++)
pow2[i] = pow2[i-1] << 1;
int t, n, k;
cin >> t;
while (t--) {
cin >> n >> k;
cout << f(k, n) << endl;
}
}