#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1},
          ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
long long gcd(long long a, long long b) {
  if (!a) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void test_case() {
  long long n, k;
  cin >> n >> k;
  if (n <= 2) {
    cout << 1 << "\n";
    return;
  }
  long long start = 3;
  long long cnt = 2;
  while (1) {
    long long last = start + k - 1;
    if (n >= start && n <= last) {
      cout << cnt << "\n";
      return;
    }
    cnt++;
    start = last + 1;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  long long t = 1;
  cin >> t;
  while (t--) {
    test_case();
  }
}
