#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    if (n % k == 0)
      cout << n << endl;
    else {
      long long int p = n / k;
      long long int t1 = n - k * p;
      long long int t2 = k / 2;
      long long int alpha = min(t1, t2);
      cout << (k - alpha) * p + (alpha) * (p + 1) << endl;
    }
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
