#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, n, t, k, j, ans;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    i = n / k;
    j = n % k;
    ans = i * k;
    ans += min(j, k / 2);
    cout << ans << "\n";
  }
}
