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