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