#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    int a, b, c;
    a = n / k;
    b = n % k;
    c = a;
    if (b <= k / 2) {
      cout << n << endl;
    } else {
      cout << n - b + k / 2 << endl;
    }
  }
  return 0;
}
