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