#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
const double pi = 3.14159265359;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    int k;
    cin >> n >> k;
    int r = n % k;
    if (r > k / 2) {
      cout << (n - r) + k / 2 << endl;
    } else {
      cout << n << endl;
    }
  }
  return 0;
}
