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