#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    ans += n / k * k;
    n = n % k;
    if (n <= (k / 2))
      ans += n;
    else
      ans += k / 2;
    printf("%d\n", ans);
  }
  return 0;
}
