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