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