#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k, i, j;
  cin >> n >> k;
  long long int arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long int pre[n];
  pre[0] = 0;
  for (i = 1; i < n; i++) {
    pre[i] = pre[i - 1] + abs(arr[i] - arr[i - 1]);
  }
  long long int mm = 1e12;
  j = 0;
  long long int l = 0;
  long long int r = 0;
  for (i = k; i < n; i++) {
    if (pre[i] - pre[j] < mm) {
      mm = pre[i] - pre[j];
      l = j;
      r = i;
    }
    j++;
  }
  cout << (arr[l] + arr[r]) / 2 << "\n";
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t > 0) {
    t--;
    solve();
  }
}
