#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, candy, kids;
  cin >> t;
  for (long long int i = 1; i <= t; i++) {
    cin >> candy >> kids;
    long long int each_get = candy / kids;
    long long int can_give = each_get * kids;
    long long int remain = candy - can_give;
    kids = kids / 2;
    long long int extra = min(remain, kids);
    can_give = can_give + extra;
    cout << can_give << endl;
  }
  return 0;
}
