#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (n % k == 0) {
      cout << n << "\n";
    } else {
      long long ans = n;
      n = n - (n % k);
      k /= 2;
      ans = min(ans, n + k);
      cout << ans << "\n";
    }
  }
}
