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