#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    k++;
    vector<int> v;
    for (int i = 0, x; i < n; i++) {
      cin >> x;
      v.push_back(x);
    }
    int act = INT_MAX;
    int p;
    for (int i = 0; i + k - 1 < n; i++) {
      if (v[i + k - 1] - v[i] < act) {
        act = v[i + k - 1] - v[i];
        p = i;
      }
    }
    int res = (v[p] + v[p + k - 1]) / 2;
    cout << res << "\n";
  }
  return 0;
}
