#include <bits/stdc++.h>
using namespace std;
int n, k;
long long int a[200005], d[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    long long int ans = 1e9, x = a[0];
    for (int i = k; i < n; ++i) {
      long long int k1 = (a[i] + a[i - k]) / 2;
      if (ans > max(k1 - a[i - k], a[i] - k1)) {
        ans = max(k1 - a[i - k], a[i] - k1);
        x = k1;
      }
    }
    cout << x << "\n";
  }
  return 0;
}
