#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x, y, b, a;
    scanf("%d %d", &x, &y);
    a = x / y;
    b = x % y;
    b = min(b, y / 2);
    x = (a * y) + b;
    cout << x << endl;
  }
  return 0;
}
