#include <bits/stdc++.h>
using namespace std;
const long long M = 1e6 + 7;
long long n, a[M], k;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long tt;
  cin >> tt;
  while (tt--) {
    cin >> n >> k;
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long ans1 = INT_MAX, ans2 = -1;
    for (long long i = k; i < n; i++) {
      if (a[i] == a[i - k]) {
        ans2 = a[i];
        break;
      }
      long long t =
          (a[i] * a[i] - a[i - k] * a[i - k]) / (2 * a[i] - 2 * a[i - k]);
      if (a[i] - t < ans1) {
        ans1 = a[i] - t;
        ans2 = t;
      }
    }
    cout << ans2 << "\n";
  }
}
