#include <bits/stdc++.h>
using namespace std;
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
const double pi = acos(-1.0);
const int mod = 1000000007;
const int maxn = 200100;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T;
  cin >> T;
  for (int z = (1); z <= (T); ++z) {
    long long n, k;
    cin >> n >> k;
    cout << (n - n % k) + min(n % k, k / 2) << "\n";
  }
  return 0;
}
