#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
bool used[105];
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int tm = 0; tm < t; tm++) {
    int n, x;
    cin >> n >> x;
    if (n == 1 or n == 2) {
      cout << "1" << '\n';
      continue;
    }
    for (int k = (n - 3) / x; k < 1000; k++) {
      if (n >= (3 + x * k) and n <= (3 + (x - 1) + x * k)) {
        cout << k + 2 << '\n';
        continue;
      }
    }
  }
  return 0;
}
