#include <bits/stdc++.h>
using namespace std;
long long t, n, k, a[1000005];
pair<long long, long long> mn;
int main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%lld", a + i);
    mn = make_pair(100000000000000007, 100000000000000007);
    k++;
    for (int i = 1; i <= n - k + 1; i++) {
      long long x = (a[i] + a[i + k - 1]) / 2;
      mn = min(mn, make_pair(max(x - a[i], a[i + k - 1] - x), x));
    }
    printf("%lld\n", mn.second);
  }
  return 0;
}
