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