#include <bits/stdc++.h>
using namespace std;
long long n, k, a[200005], idx;
bool check(long long d) {
  for (long long i = 0; i < n - k; i++) {
    if (a[i] + 2 * d >= a[i + k]) {
      idx = i;
      return true;
    }
  }
  return false;
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long lo = 0, hi = 1e9, mid;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    bool ch = check(mid), chm = check(mid - 1);
    if (ch && !chm)
      break;
    else if (ch)
      hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << a[idx] + mid << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
