#include <bits/stdc++.h>
int main() {
  std::int64_t t;
  std::cin >> t;
  while (t--) {
    std::int64_t n, k;
    std::cin >> n >> k;
    std::vector<std::int64_t> vec;
    vec.reserve(n);
    for (int i = 0; i < n; ++i) {
      std::int64_t value;
      std::cin >> value;
      vec.push_back(value);
    }
    std::int64_t min = (vec[n - 1] - vec[0] + 1) / 2;
    std::int64_t ans = vec[0] + min;
    for (int i = 0; i < n - k; ++i) {
      if (((vec[i + k] - vec[i] + 1) / 2) < min) {
        min = (vec[i + k] - vec[i] + 1) / 2;
        ans = vec[i] + min;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
