#include <bits/stdc++.h>
using namespace std;
const int MAX = 200004;
int a[MAX];
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  while (cin >> t) {
    while (t--) {
      int n, k;
      cin >> n >> k;
      for (int i = 0; i < n; i++) {
        cin >> a[i];
      }
      int len = 0x7fffffff;
      int end = -1;
      for (int i = k; i < n; i++) {
        int start = i - k;
        if (a[i] - a[start] < len) {
          len = a[i] - a[start];
          end = i;
        }
      }
      int res = (a[end - k] + a[end]) / 2;
      cout << res << "\n";
    }
  }
  return 0;
}
