#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int main() {
  int q, n, k;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int l = 0, r = 1e9 + 2, ans;
    while (l < r) {
      int mid = (l + r) / 2, ptr = 1, ch = 0;
      for (int i = 1; i <= n; i++) {
        while (ptr <= n && a[ptr] <= a[i] + 2 * mid) ++ptr;
        if (ptr - i > k) {
          ans = a[i] + mid;
          ch = 1;
          break;
        }
      }
      if (ch)
        r = mid;
      else
        l = mid + 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
