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