#include <bits/stdc++.h>
int tt, n, m, i, t1, t2, t;
long long s, x, y, min;
int main() {
  scanf("%d", &tt);
  for (; tt > 0; --tt) {
    scanf("%d%d", &n, &m);
    if (m > n / 2) m = n / 2;
    t1 = 0, t2 = n;
    while (t1 < t2) {
      t = (t1 + t2) / 2;
      s = 1LL * t * m, x = n, y = 1;
      for (i = 0; (i <= t) && (s >= 0) && (x > 0); ++i) {
        if (x < y)
          min = x;
        else
          min = y;
        x -= min;
        s -= min * i;
        y = y * (t - i) / (i + 1);
      }
      if ((s < 0) || (x > 0))
        t1 = t + 1;
      else
        t2 = t;
    }
    printf("%d\n", t1);
  }
}
