#include <bits/stdc++.h>
using namespace std;
int n, m;
bool good(long long int k) {
  long long int comb = 1, bits = (long long int)m * k, rest = n;
  for (int i = 0; i < (int)(k + 1); i++) {
    long long int take = min(rest, comb);
    bits -= i * take;
    if (bits < 0) return false;
    rest -= take;
    if (rest == 0) return true;
    comb *= k - i;
    comb /= i + 1;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    int res;
    if (m == 1)
      res = n - 1;
    else {
      int lo = -1, hi = n;
      while (lo + 1 < hi) {
        int mi = (lo + hi) / 2;
        if (good(mi))
          hi = mi;
        else
          lo = mi;
      }
      res = hi;
    }
    cout << res << '\n';
  }
  return 0;
}
