#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, x, k, m1, sum, m2, c;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    x = n / k;
    sum = x * k;
    n -= sum;
    cout << sum + min(n, k / 2) << '\n';
  }
}
