#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<long long> a;
  long long x, mink;
  long long n, k;
  unsigned t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    a.resize(n);
    for (unsigned i = 0; i < n; cin >> a[i++])
      ;
    mink = numeric_limits<long long>::max();
    for (unsigned i = 0; i + k < n; ++i) {
      long long tempx, tempmink;
      tempx = (a[i] + a[i + k]) / 2;
      tempmink = max(abs(a[i] - tempx), abs(a[i + k] - tempx));
      if (tempmink < mink) {
        mink = tempmink;
        x = tempx;
      }
    }
    cout << x << "\n";
  }
}
