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