#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const long long mod = 1e9 + 7;
int n;
int a[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = 0;
    int maxx = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (i > k) {
        int tmp = (a[i] + a[i - k] + 1) / 2;
        int w = max(tmp - a[i - k], a[i] - tmp);
        if (w < maxx) {
          maxx = w;
          ans = tmp;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
