#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, t, k, c, d, e, s, ans, p;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    c = k / 2;
    d = (k + 1) / 2;
    e = n / k;
    s = d * e;
    p = c * (e + 1);
    ans = (s + p);
    if (ans > n) ans = n;
    cout << ans << endl;
  }
  return 0;
}
