#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc, candies, kids;
  cin >> tc;
  while (tc--) {
    cin >> candies >> kids;
    cout << min(candies, (candies / kids) * kids + kids / 2) << endl;
  }
  return 0;
}
