#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int arr[MAXN];
int main() {
  int t, n, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
      scanf("%d", arr + i);
    }
    int dis = 0x3f3f3f3f;
    int x, tmp;
    for (int i = 0; i + k < n; i++) {
      tmp = (arr[i] + arr[i + k]) / 2;
      if ((arr[i + k] - tmp) < dis) {
        dis = arr[i + k] - tmp;
        x = tmp;
      }
    }
    printf("%d\n", x);
  }
  return 0;
}
