#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int indx = -1, mn = INT_MAX;
    for (int i = 0; i < n - k; i++) {
      if (abs(arr[i + k] - arr[i]) < mn) {
        mn = abs(arr[i + k] - arr[i]);
        indx = i;
      }
    }
    cout << arr[indx] + mn / 2 << endl;
  }
  return 0;
}
