#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int powll(long long int a, long long int b) {
  if (a == 1 || b == 0)
    return 1;
  else if (b % 2 == 0)
    return powll(a * a, b / 2);
  else
    return a * powll(a * a, b / 2);
}
long long int powlm(long long int a, long long int b, long long int m) {
  if (a == 1 || b == 0)
    return 1;
  else if (b % 2 == 0)
    return powlm((a * a) % m, b / 2, m);
  else
    return (a * powlm((a * a) % m, b / 2, m)) % m;
}
long long int modinv(long long int n, long long int m) {
  return powlm(n, m - 2, m);
}
long long int binsea(vector<long long int> a, long long int l, long long int r,
                     long long int x) {
  long long int mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (a[mid] == x) return mid;
    if (a[mid] < x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return -1;
}
long long int fact[1000000];
long long int nCrMp(long long int n, long long int r, long long int m) {
  if (r == 0) return 1;
  return (fact[n] * (modinv(fact[r], m) % m) * (modinv(fact[n - r], m) % m)) %
         m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  double n, x;
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n >> x;
    long long int f = 1;
    if (n > 2) {
      n -= 2;
      f += ceil(n / x);
    }
    cout << f << "\n";
  }
  return 0;
}
