#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 0;
  cin >> t;
  while (t--) {
    int n, k, c;
    cin >> n >> k;
    vector<int> a;
    for (int i = 0; i < n; i++) {
      cin >> c;
      a.push_back(c);
    }
    if (k == 0) {
      cout << a[0] << endl;
    } else {
      int min = 1000000000;
      int pos = -1;
      for (int i = 0; i < n - k; i++)
        if (a[i + k] - a[i] < min) {
          min = a[i + k] - a[i];
          pos = i;
        }
      cout << a[pos] + min / 2 << endl;
    }
  }
}
