#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    pair<int, int> ans = make_pair(INT_MAX, 0);
    for (int i = 0; i < n - k; i++) {
      int dist = a[i + k] - a[i];
      ans = min(ans, make_pair(dist, a[i] + dist / 2));
    }
    cout << ans.second << endl;
  }
  return 0;
}
