#include <bits/stdc++.h>
using namespace std;
int main() {
  long long r, x, g, h, i, n, j, t, e, a, b, k, c, l, d, f, z = 0;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    l = 1;
    if (n <= 2)
      cout << 1 << endl;
    else {
      n -= 2;
      l = 1;
      l += n / k;
      if (n % k) l++;
      cout << l << endl;
    }
  }
}
