#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long int n, k;
    scanf("%lld %lld", &n, &k);
    long long int ans = 0;
    ans += (n / k) * k;
    if (n - ans > k / 2)
      ans += k / 2;
    else
      ans = n;
    printf("%lld\n", ans);
  }
}
