#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long n, k;
long long ff(long long x) {
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    v.push_back(abs(a[i] - x));
  }
  sort(v.begin(), v.end());
  return v[k];
}
void f() {
  for (long long i = 1; i <= a[n - 1]; i++) {
    cout << i << ' ' << ff(i) << '\n';
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (k == 0) {
      cout << a[0] << '\n';
      continue;
    }
    long long mn = 1e10;
    long long p = -1;
    for (long long i = 0; i + k < n; i++) {
      long long px = a[i + k] - a[i];
      if (px < mn) {
        mn = px;
        p = a[i];
      }
    }
    cout << p + mn / 2 << '\n';
  }
  return 0;
}
