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