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