#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0', ch = getchar();
  }
  return x * f;
}
long long T, m, n;
inline bool check(long long k) {
  long long t = k * m, tmp = n, C = 1;
  for (long long i = 0; i <= k; i++) {
    long long p = min(tmp, C);
    t -= p * i;
    if (t < 0) return 0;
    tmp -= p;
    if (tmp == 0) return 1;
    C *= k - i, C /= i + 1;
  }
  return 0;
}
int main() {
  T = read();
  while (T--) {
    n = read(), m = read();
    if (m == 1)
      printf("%I64d\n", n - 1);
    else {
      long long l = -1, r = n;
      while (l + 1 < r) {
        long long mid = (l + r) >> 1;
        if (check(mid))
          r = mid;
        else
          l = mid;
      }
      printf("%I64d\n", r);
    }
  }
  return 0;
}
