#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int k, n;
    cin >> n >> k;
    int ans, b, a;
    b = n / k;
    a = b * k;
    if (n - a <= k / 2)
      ans = n;
    else
      ans = a + k / 2;
    cout << ans << endl;
  }
  return 0;
}
