#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    k++;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    long long int inf = 1000000001;
    long long int res = inf;
    long long int ind, dp;
    for (long long int i = 0; i < n - k + 1; i++) {
      dp = a[i + k - 1] - a[i];
      if (res >= dp) {
        ind = i;
        res = dp;
      }
    }
    long long int fin = a[ind] + res / 2;
    cout << fin << endl;
  }
  return 0;
}
