#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    if (n < k) {
      cout << min(n, k / 2) << endl;
      continue;
    }
    if (k == 1 || k == 0) {
      cout << n << endl;
      continue;
    }
    long int z = (long)(k * (n / k) + min(k / 2, n % k));
    cout << z << endl;
  }
}
