#include <bits/stdc++.h>
using namespace std;
int main() {
  int y;
  cin >> y;
  for (int i = 0; i < y; i++) {
    int n, k, ans = 0;
    cin >> n >> k;
    ans = ((n % k) >= (k / 2)) ? ((n / k) * k + (k / 2)) : n;
    cout << ans << endl;
  }
  return 0;
}
