#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    int temp = n / k;
    if (n % k >= k / 2) {
      int result = (temp * k) + (k / 2);
      cout << result << endl;
    } else {
      cout << n << endl;
    }
  }
  return 0;
}
