#include <bits/stdc++.h>
using namespace std;
int T, n, m;
inline bool ok(long long k) {
  long long t = k * m, cnt = 1, tmp = 1;
  for (long long i = 1; i <= k; i++) {
    tmp = tmp * (k - i + 1) / i;
    if (i <= t / tmp)
      t -= i * tmp, cnt += tmp;
    else {
      cnt += t / i;
      break;
    }
  }
  return cnt >= n;
}
inline long long calc() {
  long long l = 0, r = n;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (ok(mid))
      r = mid;
    else
      l = mid + 1;
  }
  return r;
}
int main() {
  for (scanf("%d", &T); T--;) {
    scanf("%d%d", &n, &m);
    if (m + m > n) m = n / 2;
    printf("%I64d\n", calc());
  }
}
