#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long ar[n];
    for (long long i = 0; i < n; i++) cin >> ar[i];
    sort(ar, ar + n);
    long long x;
    long long mi = INT_MAX;
    for (long long i = 0; i < n - k; i++) {
      if (ar[i + k] - ar[i] < mi) {
        mi = ar[i + k] - ar[i];
        x = ar[i] + mi / 2;
      }
    }
    cout << x << "\n";
  }
  return 0;
}
