#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b, c, x, y, z, w;
    cin >> x >> y;
    z = x / y;
    w = x % y;
    int ans = (z * y) + min(w, y / 2);
    cout << ans << endl;
  }
  return 0;
}
