#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    map<double, long long> ko;
    int n, k;
    cin >> n >> k;
    double a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    double p[n];
    for (int i = 0; i < n - k; i++) {
      p[i] = abs(a[i + k] - a[i]) / 2;
      ko[abs(a[i + k] - a[i]) / 2] = abs(a[i + k] + a[i]) / 2;
    }
    sort(p, p + n - k);
    cout << ko[p[0]] << endl;
  }
  return 0;
}
