#include <bits/stdc++.h>
using namespace std;
long long x[1000000];
int main() {
  long long a, b, c, d, e, i, j, k = 0, z = 0, m, n = 0;
  cin >> a;
  while (a--) {
    cin >> b >> c;
    d = b % c;
    e = c / 2;
    if (b % c == 0) {
      cout << b << endl;
    } else if (b < c) {
      if ((c / 2) > b) {
        cout << b << endl;
      } else {
        cout << c / 2 << endl;
      }
    } else {
      if (d <= e) {
        cout << b << endl;
      } else {
        j = d - e;
        cout << b - j << endl;
      }
    }
  }
}
