#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i = 0, j = 0, k = 0, n = 0, t = 0, s = 0, h = 0, m = 0, rem = 0,
                remj = 0;
  cin >> t;
  while (t > 0) {
    s = 0;
    int d = 0;
    cin >> n >> k;
    rem = n % k;
    j = k / 2;
    s = n - rem;
    s += min(rem, j);
    cout << s << endl;
    t--;
  }
  return 0;
}
