#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, x;
  cin >> n >> k;
  k++;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  long long ans = 1e18;
  long long mn = 1e18;
  for (long long i = 0; i <= n - k; i++) {
    long long p1 = v[i];
    long long p2 = v[i + k - 1];
    long long p = (p2 + p1) / 2;
    if (mn > p2 - p) {
      mn = p2 - p;
      ans = p;
    }
  }
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  cout << fixed;
  long long t;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
