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