#include <bits/stdc++.h>
using namespace std;
int t, n, k, a[200009], ans, mx;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    mx = 1e9 + 9;
    cin >> n >> k;
    for (int i = 0; i < k; i++) cin >> a[i];
    for (int i = k; i < n; i++) {
      cin >> a[i];
      int dif = a[i] - a[i - k];
      if (dif < mx) {
        mx = dif;
        ans = a[i - k] + (a[i] - a[i - k]) / 2;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
