#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    if (n == 1 || n == 2) {
      cout << 1 << '\n';
    } else {
      long long i = 0;
      while (true) {
        long long a = i * x + 3;
        long long b = (i + 1) * x + 2;
        if (n >= a && n <= b) {
          break;
        }
        i++;
      }
      cout << i + 2 << '\n';
    }
  }
}
