#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long n;
    long long x;
    cin >> n >> x;
    if (n <= 2) {
      cout << 1 << endl;
    } else {
      long long k = (n - 2) / x;
      if (k * x == (n - 2)) {
        cout << 1 + k << endl;
      } else {
        cout << 2 + k << endl;
      }
    }
  }
  return 0;
}
