#include <bits/stdc++.h>
using namespace std;
char vowel[6] = {'a', 'e', 'i', 'o', 'u', 'y'};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t, i, j, n, k, p, q, res;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    p = n / k;
    q = k / 2;
    res = (p * k);
    if (k / 2 <= n - res)
      res += (k / 2);
    else if (k / 2 > n - res)
      res += (n - res);
    cout << res << "\n";
  }
  return 0;
}
