#include <bits/stdc++.h>
using namespace std;
long n, m, l, r, T, mid;
bool check(long long x) {
  long long p = x * m, s = 1, d = n, t;
  for (long i = 0; i <= x && p >= 0 && d; i++) {
    d -= (t = min(s, d));
    p -= t * i;
    s = s * (x - i) / (i + 1);
  }
  return p >= 0 && !d;
}
int main() {
  for (scanf("%ld", &T); T; T--) {
    scanf("%ld%ld", &n, &m);
    m = min(m, n / 2);
    l = 0;
    r = n;
    while (l < r) {
      mid = (l + r) / 2;
      if (check(mid))
        r = mid;
      else
        l = mid + 1;
    }
    printf("%ld\n", r);
  }
  return 0;
}
