#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 60) - 1;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ans = n - (n % k);
    int cnt = k / 2;
    ans += min(n % k, cnt);
    cout << ans << endl;
  }
  return 0;
}
