#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<long long> v;
    for (int i = 1; i <= n; i++) {
      long long x;
      scanf("%lld", &x);
      v.push_back(x);
    }
    if (k == 0) {
      cout << v[0] << endl;
    } else {
      long long ans = 0;
      long long val = 1e10;
      for (int i = 0; i + k < n; i++) {
        long long now = (v[i + k] + v[i]) / 2LL;
        long long mi = max(abs(now - v[i]), abs(v[i + k] - now));
        if (val > mi) {
          val = mi;
          ans = now;
        }
      }
      cout << ans << endl;
    }
    v.clear();
  }
}
