#include <bits/stdc++.h>
using namespace std;
long long fpm(long long b, long long e, long long m) {
  long long t = 1;
  for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
  return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class edge>
struct Graph {
  vector<vector<edge> > adj;
  Graph(int n) {
    adj.clear();
    adj.resize(n + 5);
  }
  Graph() { adj.clear(); }
  void resize(int n) { adj.resize(n + 5); }
  void add(int s, edge e) { adj[s].push_back(e); }
  void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); }
  int deg(int v) { return adj[v].size(); }
  vector<edge> &operator[](int t) { return adj[t]; }
};
bool check(int n, int m, int k) {
  long long t = (long long)m * k, inf = 1e18;
  double C = 1;
  for (int i = 0; i <= k && i <= t; ++i) {
    long long p = min(i ? (t / i) : inf, C > inf ? inf : (long long)C);
    if (n <= p) return true;
    n -= p, t -= p * i;
    C = C * (k - i) / (i + 1);
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  int T, n, m;
  cin >> T;
  for (; T--;) {
    cin >> n >> m;
    int L = 0, R = n, k;
    for (; k = (L + R) >> 1, L < R;) check(n, m, k) ? (R = k) : (L = k + 1);
    cout << k << endl;
  }
  return 0;
}
