#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx2,avx,fma")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int i, j, t;
  cin >> t;
  for (i = 0; i < t; i++) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (j = 0; j < n; j++) cin >> a[j];
    if (k == 0) {
      cout << a[0] << "\n";
      continue;
    }
    int mini = 1e9;
    int pos = -1;
    for (j = k; j < n; j++)
      if (mini > a[j] - a[j - k]) {
        mini = a[j] - a[j - k];
        pos = j - k;
      }
    cout << a[pos] + (a[pos + k] - a[pos]) / 2 << "\n";
  }
  return 0;
}
