#include <bits/stdc++.h>
using namespace std;
int n, m, T;
bool check(int v) {
  if (n == 1) return 1;
  long long c = 1, cnt = 1ll * v * m;
  int lft = n;
  for (int i = 1; i <= v; i++) {
    if (cnt < i) return 0;
    if (c * (v - i + 1) > 1ll * n * i)
      c = n;
    else
      c = c * (v - i + 1) / i;
    long long tmp = min(cnt / i, c);
    lft -= tmp;
    if (lft <= 1) return 1;
    cnt -= tmp * i;
  }
  return 0;
}
void solve() {
  scanf("%d%d", &n, &m);
  int l = 0, r = n, ret = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ret = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ret);
}
int main() {
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
