#include <bits/stdc++.h>
const int MAXN = 200005;
int a[MAXN], n, k;
void getInter(int l, int r, int &x, int &y) {
  x = l + (r - l) / 2;
  y = (r - l + 1) / 2;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int ans = -1, min = 1000000000;
    for (int i = 0, x, y; i + k < n; i++) {
      getInter(a[i], a[i + k], x, y);
      if (y < min) {
        min = y;
        ans = x;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
