#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a, b;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d", &a, &b);
    if (a == 1 or a == 2)
      cout << 1 << endl;
    else {
      for (int i = 1; 1 > 0; i++) {
        if (((i - 1) * b + 3) <= a and (i * b + 2) >= a) {
          cout << i + 1 << endl;
          break;
        }
      }
    }
  }
  return 0;
}
