#include <bits/stdc++.h>
const int MAXN = 2e5 + 5;
int a[MAXN], T, n, k;
inline void Solve() {
  scanf("%d%d", &n, &k);
  for (register int i = 1; i <= n; ++i) scanf("%d", a + i);
  int ans = k + 1;
  for (register int i = 1; i <= n; ++i) {
    if (i > k && a[i] - a[i - k] < a[ans] - a[ans - k]) {
      ans = i;
    }
  }
  printf("%d\n", (a[ans] + a[ans - k]) / 2);
}
int main() {
  scanf("%d", &T);
  while (T--) Solve();
  return 0;
}
