#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
void speedUpIO() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1e9;
const long long int LINF = 1e18;
const int MAX = 100010;
void solve() {
  int n, k;
  cin >> n >> k;
  int ans = n - n % k;
  ans += k / 2;
  chmin(ans, n);
  cout << ans << "\n";
}
int main() {
  speedUpIO();
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
