#include <bits/stdc++.h>
using namespace std;
bool debug = true;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> ptt) {
  os << ptt.first << "," << ptt.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vt) {
  os << "{";
  for (int i = 0; i < vt.size(); i++) {
    os << vt[i] << " ";
  }
  os << "}";
  return os;
}
int n, k;
int a[200005];
int main(int argc, char* argv[]) {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int mx = 0;
    for (int i = 0; i < n - k; i++) {
      if (a[i + k] - a[i] < a[mx + k] - a[mx]) {
        mx = i;
      }
    }
    cout << (a[mx + k] + a[mx]) / 2 << endl;
  }
  return 0;
}
