#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 0;
  cin >> t;
  while (t--) {
    int a = 0;
    int c = 0;
    cin >> c >> a;
    int m = c / a;
    if (c - m * a <= a / 2) {
      cout << c;
    } else {
      cout << m * a + a / 2;
    }
    cout << "\n";
  }
}
