#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
bool check(long long t) {
  long long cnt = m * t, N = 0, i = 0, c = 1;
  bool f = 1;
  while (i <= t && cnt || f) {
    f = 0;
    if (cnt >= c * (i)) {
      cnt -= c * i;
      N += c;
    } else {
      long long now = cnt / i;
      N += now;
      cnt = 0;
    }
    i++;
    c = c * (t - i + 1) / (i);
    if (N >= n) return 1;
  }
  return (N >= n);
}
void solve() {
  cin >> n >> m;
  long long l = -1, r = 1e9 + 1;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
}
int main() {
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
