#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  int flag = 1;
  x = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  x *= flag;
}
int main() {
  int t, n, k;
  read(t);
  while (t--) {
    read(n);
    read(k);
    printf("%d\n", (n / k * k) + (((n % k) > (k / 2)) ? k / 2 : n % k));
  }
  return 0;
}
