#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    int i;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    int dist = INT_MAX;
    for (i = k + 1; i <= n; i++) {
      int mid = (a[i] + a[i - k]) / 2;
      int temp = max(a[i] - mid, mid - a[i - k]);
      if (temp < dist) {
        ans = mid;
        dist = temp;
      }
    }
    cout << ans << endl;
  }
}
