#include <bits/stdc++.h>
using namespace std;
bool iseven(long long n) {
  if (n % 2 == 0)
    return true;
  else {
    return false;
  }
}
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
void print(vector<int> a, int n) {
  for (int i = 0; i < n; i += 1) cout << a[i] << " ";
}
bool sec(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second > b.second);
  else {
    return (a.first > b.first);
  }
}
void print1(int y) {
  if (y == 1)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
}
void fun(vector<int> &v, unordered_map<int, int> m, vector<int> a, int n,
         int re, int mi, int ma) {
  int pos = m[re];
  while (pos != n - 1) {
    v.push_back(re);
    if (re == mi) {
      mi++;
      re = ma;
    } else {
      ma--;
      re = mi;
    }
    pos = m[re];
  }
  v.push_back(re);
}
int fun1(vector<int> a) {
  int s = 0;
  for (int i = 0; i < a.size() - 1; i += 1) {
    s += abs(a[i] - a[i + 1]);
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    if (n % k == 0)
      ans = n;
    else {
      ans = (n / k) * k;
      long long r = n % k;
      if ((k / 2) < r)
        ans += (k / 2);
      else {
        ans += r;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
