#include <bits/stdc++.h>
using namespace std;
void read1D(int A[], int n) {
  for (int i = 0; i < n; i++) cin >> A[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n];
    read1D(a, n);
    int ind = 0;
    for (int i = 0; i + k < n; i++) {
      if (a[i + k] - a[i] < a[ind + k] - a[ind]) ind = i;
    }
    cout << (a[ind] + a[ind + k]) / 2 << "\n";
  }
}
