#include <bits/stdc++.h>
using namespace std;
long long C_n_k(int n, int k) {
  if (k == 0) return 1;
  long long res = 1;
  int t1 = k, t2 = n - k;
  if (t1 < t2) swap(t1, t2);
  int curr_n = t1 + 1;
  for (int i = 1; i <= t2; i++) {
    while (res % i != 0) res *= (curr_n++);
    res /= i;
  }
  while (curr_n <= n) res *= (curr_n++);
  return res;
}
bool is_enough(int n, int k, int m) {
  long long c1 = (long long)m * k, c2 = 1;
  for (int i = 1; i <= k && c1 / i > 0; i++) {
    long long tmp = C_n_k(k, i);
    c2 += min(c1 / i, tmp);
    c1 -= min(c1 / i, tmp) * i;
    if (c2 >= n) return true;
  }
  return false;
}
int main() {
  int t;
  cin >> t;
  for (; t > 0; --t) {
    int n, m;
    cin >> n >> m;
    int l = 0, r = 1e9;
    if (n == 1) l = 0, r = 0;
    while (r > l) {
      int mid = (r + l) / 2;
      if (is_enough(n, mid, m))
        r = mid;
      else
        l = mid + 1;
    }
    cout << l << "\n";
  }
}
