#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x;
  cin >> n >> x;
  if (n <= 2) {
    cout << 1 << "\n";
    return;
  }
  cout << 1 + (n - 3 + x) / x << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
