#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int n, k;
    cin >> n >> k;
    int full = n - n % k;
    full += min(n % k, k / 2);
    cout << full << endl;
  }
}
