#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    long long arr[n];
    for (long long i = 0; i < n; i++) cin >> arr[i];
    long long ans = INT_MAX, j = -1;
    for (long long i = 0; i + k < n; i++) {
      if (ans > arr[i + k] - arr[i]) {
        ans = arr[i + k] - arr[i];
        j = i;
      }
    }
    cout << (arr[j] + arr[j + k]) / 2 << endl;
  }
  return 0;
}
