#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int c, s, v = 0, m, d, k, y;
    cin >> c >> s;
    m = (s / 2);
    d = (c / s);
    k = (c % s);
    if (m == 0) {
      v = c;
    } else {
      if (k >= m) {
        v = (c - k + m);
      } else {
        v = c;
      }
    }
    cout << v << endl;
  }
  return 0;
}
