#include <bits/stdc++.h>
using namespace std;
int n, k, T, a[200010];
struct node {
  int x, y;
  node(int t1, int t2) { x = t1, y = t2; }
  bool operator<(const node &s1) const { return x > s1.x; }
};
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    priority_queue<node> q;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i + k <= n; i++) {
      q.push(node(a[i + k] - a[i], a[i] + ((a[i + k] - a[i]) / 2)));
    }
    cout << q.top().y << endl;
  }
  return 0;
}
