#include <bits/stdc++.h>
using namespace std;
long long ar[200001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, n, k, val, ans, v;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> ar[i];
    ans = 1000000000;
    for (int i = 0; i + k < n; i++) {
      val = (ar[i + k] - ar[i]);
      val = val / 2 + val % 2;
      if (val < ans) {
        ans = val;
        v = ar[i] + val;
      }
    }
    cout << v << endl;
  }
}
