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