#include <bits/stdc++.h>
long long inf = (long long)1e18;
using namespace std;
int expo(int base, int exponent) {
  int ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (1LL * ans * base) % 1000000007;
    base = (1LL * base * base) % 1000000007;
    exponent >>= 1;
  }
  return ans % 1000000007;
}
int solve() {
  long long n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << n << '\n';
    return 0;
  }
  long long ans = k * (n / k);
  ans += min(k / 2, n % k);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
