#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int maxn = 5e5 + 10;
const int inf = 2e9;
const int maxm = 1e4 + 10;
const int mod = 998244353;
int a[maxn];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    if (k == 0) {
      printf("%d\n", a[1]);
      continue;
    }
    long long Min = 2e9;
    long long ans;
    for (int i = 1; i + k <= n; i++) {
      if (a[i + k] - a[i] < Min) {
        Min = a[i + k] - a[i];
        ans = 1LL * (a[i + k] + a[i]) / 2;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
