#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using p = pair<int, int>;
const int INF = 0x66554433;
inline void quick_IO() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int main() {
  quick_IO();
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    int counts = 2;
    int temp = 1;
    cin >> n >> x;
    if (n == 1 || n == 2) {
      cout << "1\n";
      continue;
    }
    for (int i = 3; i < n; i++) {
      if ((i - 2) % x == 0) {
        counts++;
      }
    }
    cout << counts << "\n";
  }
  return 0;
}
