#include <bits/stdc++.h>
int min(int x, int y) { return (y & -(x > y)) + (x & -!(x > y)); }
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    int e;
    scanf("%d %d", &n, &k);
    e = k * (n / k);
    printf("%d\n", e + min(n - e, k >> 1));
  }
  return 0;
}
