#include <bits/stdc++.h>
const int INF = (int)1e9 + 7;
int f(const std::vector<int> &arr, int k, int d) {
  std::list<std::pair<int, int>> events, se;
  for (auto &it : arr) {
    events.push_back({it - d, 0});
    se.push_back({it + d, 1});
  }
  events.merge(se);
  int bal = 0;
  for (auto it : events) {
    bal += (it.second ? -1 : +1);
    if (bal > k) {
      return it.first;
    }
  }
  return -INF;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  int t;
  std::cin >> t;
  while (t--) {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> arr(n);
    for (auto &it : arr) {
      std::cin >> it;
    }
    std::sort((arr).begin(), (arr).end());
    int low = -1, high = (int)1e9;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (f(arr, k, mid) > -INF) {
        high = mid;
      } else {
        low = mid;
      }
    }
    std::cout << f(arr, k, high) << "\n";
  }
  return 0;
}
