#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, k, p, q, o, l, s, t;
  cin >> n;
  while (n--) {
    cin >> p >> q;
    k = p / q;
    s = q * k;
    s += q / 2;
    if (s > p) {
      s = p;
    }
    cout << s << endl;
  }
  return 0;
}
