#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 7;
const long long Maxll = 1e18 + 7;
const int inf = 1e9 + 7;
int t;
int n, k;
int aa[Maxn];
long long ans;
long long pre[Maxn];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &aa[i]);
    sort(aa + 1, aa + 1 + n);
    long long Minsum = Maxll;
    int dot;
    for (int i = 1; i <= n - k; i++) {
      long long dec = aa[i + k] - aa[i];
      if (dec < Minsum) {
        Minsum = dec;
        dot = i;
      }
    }
    ans = (aa[dot] + aa[dot + k]) / 2;
    printf("%lld\n", ans);
  }
  return 0;
}
