#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0LL);
  cin.tie(0LL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    cout << ((n / k) * k) + min(k / 2, (n % k)) << '\n';
  }
}
