#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
long long int power(long long int i, long long int j) {
  long long int prod = 1;
  while (j > 0) {
    if (j & 1) {
      prod = prod * i;
    }
    j = j >> 1;
    i = i * i;
  }
  return prod;
}
string numtostring(long long int num) {
  string s = "";
  if (num == 0) {
    return "0";
  }
  while (num > 0) {
    if (num % 2 == 0) {
      s += "0";
    } else {
      s += "1";
    }
    num = num / 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
long long int binarystringtonum(string s) {
  string tmp = s;
  long long int dec = 0;
  long long int base = 1, i, j;
  for (i = tmp.size() - 1; i >= 0; i--) {
    if (tmp[i] == '1') {
      dec += base;
    }
    base = 2 * base;
  }
  return dec;
}
void solve() {
  long long int i, j, k, n, m, l, x;
  cin >> n >> x;
  if (n == 1 || n == 2) {
    cout << "1\n";
    return;
  }
  k = floor((n - 3) / x);
  cout << k + 2 << endl;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
