#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int T;
int n, k;
int a[maxn];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", a + i);
    pair<int, int> ans = {1e9 + 7, -1};
    for (int i = 1; i <= n - k; i++) {
      int dist = a[i + k] - a[i];
      ans = min(ans, make_pair(dist, (a[i + k] + a[i]) / 2));
    }
    printf("%d\n", ans.second);
  }
  return 0;
}
