#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long res = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
  return res * f;
}
long long t;
signed main() {
  t = read();
  while (t--) {
    long long n = read();
    long long x = read();
    if (n <= 2) {
      cout << 1 << endl;
    } else {
      if ((n - 2) % x == 0)
        cout << (n - 2) / x + 1 << endl;
      else
        cout << (n - 2) / x + 2 << endl;
    }
  }
  return 0;
}
