#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000009;
long long mod = 998244353;
long long n, kek[MAX];
vector<long long> child[MAX];
long long bin(long long num, long long power) {
  if (power == 0)
    return 1;
  else {
    long long an = (num) % mod;
    if (power % 2 == 0) {
      an = bin(num, power / 2);
      long long an1 = an;
      an *= an1;
      an %= mod;
      return an;
    } else {
      an *= bin(num, power - 1);
      an %= mod;
      return an;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n, k;
    cin >> n >> k;
    if (n % k <= k / 2) {
      cout << n << "\n";
    } else
      cout << n - ((n % k) - k / 2) << "\n";
  }
  return 0;
}
