#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unsigned long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    unsigned long long ans = 1e9, idx = -1;
    for (int i = 0; i < n; i++) {
      if (i + k == n) break;
      if (ans > a[i + k] - a[i]) {
        ans = a[i + k] - a[i];
        idx = i;
      }
    }
    cout << a[idx] + (a[idx + k] - a[idx]) / 2 << endl;
  }
  return 0;
}
