#include <bits/stdc++.h>
using namespace std;
const int N = int(5e4) + 10;
int t, n, k;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cout << (n / k) * k + min(k / 2, n % k) << '\n';
  }
}
