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