#include <bits/stdc++.h>
const int maxn = 1e5 * 2 + 20;
using namespace std;
int t;
int a, b;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> a >> b;
    int tt = 0;
    tt = (a / b) * b;
    int rem = a - ((a / b) * b);
    tt += min(rem, b / 2);
    cout << tt << endl;
  }
  return 0;
}
