#include <bits/stdc++.h>
using namespace std;
const long long INF = 2147483647;
const long long L = 4294967296;
long long a[200005];
int main() {
  int i, j = 0;
  int t;
  int n, k;
  int temp;
  long long sum, mmin, poi, xb;
  scanf("%d", &t);
  while (t--) {
    sum = 0;
    scanf("%d%d", &n, &k);
    k++;
    for (i = 1; i <= n; i++) {
      scanf("%I64d", &a[i]);
    }
    mmin = +INF;
    for (i = k; i <= n; i++) {
      if (a[i] - a[i - k + 1] < mmin) {
        mmin = a[i] - a[i - k + 1];
        poi = a[i - k + 1] + mmin / 2;
      }
    }
    printf("%I64d\n", poi);
  }
  return 0;
}
