#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool judge(long long k) {
  if (n == 1) return 1;
  long long num = (long long)m * k, res = 1, C = 1;
  for (int i = 1; i <= k; i++) {
    if (num < i) return 0;
    if ((long long)(k - i + 1) * C >= (long long)n * i)
      C = n;
    else
      C = C * (k - i + 1) / i;
    long long temp = min(num / i, C);
    res += temp;
    if (res >= n) return 1;
    num -= temp * i;
  }
  return 0;
}
int main() {
  long long T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    long long l = 0, r = n, mid, ans;
    while (l <= r) {
      mid = (l + r) / 2;
      if (judge(mid)) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << ans << endl;
  }
}
