#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    double div = n / (double)k;
    long long p1 = floor(div), p2 = ceil(div);
    long long ans = p1 * k;
    long long rem = n - ans;
    long long giv = k / 2;
    ans += min(rem, giv);
    cout << ans << endl;
  }
}
