#include <bits/stdc++.h>
using namespace std;
void input() {
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    long long n, k;
    cin >> n >> k;
    int besi = k / 2;
    if (n % k == 0)
      cout << n << endl;
    else {
      long long p = n % k;
      long long sum = n / k;
      sum = sum * k;
      if (besi <= p)
        cout << sum + besi << endl;
      else
        cout << sum + p << endl;
    }
  }
}
