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