#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10e2 + 5;
int tt, n, m;
int matriz[MAXN][MAXN];
long long ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> tt;
  while (tt--) {
    cin >> n >> m;
    int atual = 1, t = 2;
    while (t < n) {
      atual++;
      t += m;
    }
    cout << atual << endl;
  }
  return 0;
}
