#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
void solve() {
  int n, k;
  cin >> n >> k;
  int ans = n / k * k;
  ans += min(n - ans, k / 2);
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
