#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    if (n % k == 0) {
      cout << n << endl;
    } else if (n < k) {
      if (n < k / 2) {
        cout << n << endl;
      } else {
        cout << k / 2 << endl;
      }
    } else {
      long long int a = n / k;
      long long int bm = k / 2;
      long long int ba = n % k;
      if (bm >= ba) {
        cout << n << endl;
      } else {
        cout << a * k + bm << endl;
      }
    }
  }
}
