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