#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> k >> n;
    int r = n / 2;
    cout << (k / n) * n + min(k - (k / n) * n, r) << "\n";
  }
}
