#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int ans = n / k;
  int res = n - k * (n / k);
  cout << (ans + 1) * min(res, (k / 2)) + (ans) * (k - min(k / 2, res)) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }
  return 0;
}
