#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int a[N];
int n, k;
int solve() {
  cin >> n >> k;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  int ans = -1, mini = 1e9 + 19;
  for (int r = (k + 1); r <= (n); r++) {
    int l = r - k;
    int lo = a[l], hi = a[r];
    int mid = a[l] + (a[r] - a[l]) / 2, cur;
    cur = max(mid - lo, hi - mid);
    if (cur < mini) {
      mini = cur;
      ans = mid;
    }
    mid++;
    cur = max(mid - lo, hi - mid);
    if (cur < mini) {
      mini = cur;
      ans = mid;
    }
  }
  cout << ans << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
