#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
int t, n, a[maxn], x;
void fun() {
  cin >> n >> x;
  if (n < 3) {
    cout << 1 << endl;
    return;
  } else
    cout << (n - 3 + x) / x + 1 << endl;
}
int main() {
  cin >> t;
  while (t--) {
    fun();
  }
  return 0;
}
