#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k, ans = 1.5e9, rans;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - k; i++) {
    ans = min(ans, (-a[i] + a[i + k] + 1) / 2);
    if (ans == (-a[i] + a[i + k] + 1) / 2) rans = (a[i] + a[i + k]) / 2;
  }
  cout << rans << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
