#include <bits/stdc++.h>
using namespace std;
namespace MY {
int T, n, m;
int ans;
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= (ch == '-');
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f ? -x : x;
}
bool judge(int a) {
  if (n == 1) return true;
  long long sum = 0, num = 1;
  long long tmp = 1;
  for (int i = 1; i <= a; i++) {
    tmp = tmp * (a - i + 1) / i;
    sum += tmp * i;
    num += tmp;
    if (num >= n) return sum - (num - n) * i <= 1ll * a * m;
  }
  return false;
}
void solve() {
  n = read();
  m = read();
  int l = 0, r = n - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (judge(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
}
int work() {
  T = read();
  for (int i = 1; i <= T; i++) solve();
  return 0;
}
}  // namespace MY
int main() { return MY::work(); }
