#include <bits/stdc++.h>
using namespace std;
const long long RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ob == ib) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ob == ib) ? EOF : *ib++;
}
inline long long read() {
  char ch = getchar();
  long long res = 0, f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = getchar();
  return f ? res : -res;
}
const long long N = 200005;
long long T, n, k;
long long a[N];
signed main() {
  T = read();
  while (T--) {
    n = read(), k = read();
    generate(a + 1, a + n + 1, read);
    long long mx = 2e9, pos = a[1];
    for (long long i = 1; i <= n - k; i++) {
      long long now = a[i + k] - a[i];
      if (now <= mx) mx = now, pos = (a[i + k] + a[i]) / 2;
    }
    cout << pos << '\n';
  }
}
