#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    int n, k, x, y, s = 0, d = INT_MAX, r;
    scanf("%d", &n);
    scanf("%d", &k);
    int a[n];
    for (j = 0; j < n; j++) {
      scanf("%d", &a[j]);
    }
    for (j = k; j < n; j++) {
      y = (a[j] - a[j - k] + 1) / 2;
      if (y < d) x = (a[j] + a[j - k]) / 2;
      d = min(d, y);
    }
    cout << x << '\n';
  }
}
