#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  long long i, j;
  for (i = 0; i < t; i++) {
    long long n, k;
    cin >> n >> k;
    long long b[n], m = 0, l = 0;
    for (j = 0; j < n; j++) cin >> b[j];
    long long c = 0;
    long long min = INT_MAX;
    for (m = 0; m < n - k; m++) {
      long long sum = 0;
      sum += b[m + k] - b[m];
      if (sum < min) {
        min = sum;
        c = m;
      }
    }
    cout << (b[c] + b[c + k]) / 2 << endl;
  }
}
