#include <bits/stdc++.h>
using namespace std;
int t, n, k, mn;
long long ans;
int a[200005];
int main() {
  scanf("%d", &t);
  while (t--) {
    mn = 1 << 30;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n - k; i++) {
      if (a[i + k] - a[i] < mn) {
        mn = a[i + k] - a[i];
        ans = (long long)(a[i + k] + a[i]) / 2;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
