#include <bits/stdc++.h>
int T, n, k, a[210000], mi, x, te;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    mi = a[1 + k] - a[1];
    x = (a[1 + k] + a[1]) >> 1;
    for (int i = 2; i <= n - k; i++) {
      te = a[i + k] - a[i];
      if (te < mi) {
        mi = te;
        x = (a[i + k] + a[i]) >> 1;
      }
    }
    printf("%d\n", x);
  }
  return 0;
}
