#include <bits/stdc++.h>
using namespace std;
const int mod = 1e+9 + 7;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void solve() {
  int n, k, start, end;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  start = 0, end = k;
  int min = a[k] - a[0];
  for (int i = 1; i < n - k; i++) {
    if ((a[i + k] - a[i]) < min) {
      start = i;
      end = i + k;
      min = a[i + k] - a[i];
    }
  }
  cout << (a[start] + a[end]) / 2 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
