#include <bits/stdc++.h>
using namespace std;
int read_int() {
  int result = 0;
  char ch;
  ch = getchar();
  while (true) {
    if (ch >= '0' && ch <= '9') break;
    ch = getchar();
  }
  result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    result = result * 10 + (ch - '0');
  }
  return result;
}
int solve(int n, int x) {
  if (n <= 2)
    return 1;
  else {
    n = n - 2;
    if (n % x == 0)
      return (n / x) + 1;
    else
      return (n / x) + 2;
  }
}
int main() {
  int T;
  vector<int> N;
  vector<int> X;
  T = read_int();
  for (int i = 0; i < T; i++) {
    N.push_back(read_int());
    X.push_back(read_int());
  }
  for (int i = 0; i < T; i++) {
    printf("%d\n", solve(N[i], X[i]));
  }
  return 0;
}
