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