#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int N, K;
    cin >> N >> K;
    int sum = N - N % K;
    sum += min(N % K, K / 2);
    cout << sum << endl;
  }
}
