#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b;
    int total = 0;
    scanf("%d %d", &a, &b);
    int o = a / b;
    int t = (int)ceil(1.0 * a / b);
    int p = b / 2;
    total = t * p + o * (b - p);
    if (total <= a)
      printf("%d\n", total);
    else
      printf("%d\n", a);
  }
  return 0;
}
