#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  int can = n / k;
  int rem = n % k;
  cout << (n / k) * k + min(k / 2, rem) << endl;
}
int main() {
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
