#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
long long T, n, m, wz, ans, a[N];
long long pd(long long mid) {
  long long r = 1, res = 0;
  for (long long i = 1; i <= n; i++) {
    while (r <= n && a[r] - a[i] <= mid * 2) r++;
    res = max(res, r - i);
    if (r - i >= m + 1) wz = (a[i] + a[r - 1]) / 2;
  }
  if (res >= m + 1)
    return 1;
  else
    return 0;
}
signed main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld", &n, &m);
    for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
    long long l = 0, r = 1e9, ans = 1e9;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (pd(mid))
        ans = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    pd(ans);
    printf("%d\n", wz);
  }
  return 0;
}
