#include <bits/stdc++.h>
using namespace std;
namespace _lo {
const int N = 200000;
void run() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (--t >= 0) {
    int n, k;
    cin >> n >> k;
    static int a[N + 1];
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int res = -1, res_val = INT_MAX;
    for (int i = 1; i + k <= n; ++i) {
      int j = i + k;
      int cur = (a[i] + a[j]) / 2;
      int cur_val = max(a[j] - cur, cur - a[i]);
      if (cur_val < res_val) {
        res = cur;
        res_val = cur_val;
      }
    }
    cout << res << '\n';
  }
}
}  // namespace _lo
int main() { _lo::run(); }
