#include <bits/stdc++.h>
using namespace std;
long long solve(long long n, long long x) {
  if (n == 1 || n == 2)
    return 1;
  else {
    n = n - 2;
    if (n % x == 0)
      return n / x + 1;
    else
      return n / x + 2;
  }
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    cout << solve(n, x) << endl;
  }
}
