#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n, k;
    cin >> n >> k;
    int t = (n / k);
    t *= k;
    cout << t + min(n % k, k / 2) << endl;
  }
}
