#include <bits/stdc++.h>
using namespace std;
long long a[200009];
int main() {
  long long T, n, k, i, daan, tmp, res;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    for (i = 1; i <= n; i++) cin >> a[i];
    long long ans = 0x7fffffff;
    for (i = 1; i + k <= n; i++) {
      tmp = (a[i] + a[i + k]) / 2;
      res = max(tmp - a[i], a[i + k] - tmp);
      if (ans > res) {
        ans = res;
        daan = tmp;
      }
    }
    cout << daan << endl;
  }
  return 0;
}
