#include <bits/stdc++.h>
bool debug = 0;
const long long MOD = 1000000007;
const double PI = acos(-1.0);
const double eps = 1e-9;
using namespace std;
int n, k;
long long a[200100];
int main() {
  int t;
  cin >> t;
  while (t--) {
    scanf("%d %d", &n, &k);
    for (int i = (0); i < (n); i++) scanf("%lld", &a[i]);
    k++;
    int res = 2000000000, id;
    for (int i = (0); i < (n - k + 1); i++) {
      long long x = (a[i + k - 1] - a[i]);
      if (debug)
        cout << "x"
             << " = " << (x) << endl;
      if (res > (x + 1) / 2) {
        res = (x + 1) / 2;
        id = (x + 1) / 2 + a[i];
      }
    }
    cout << id << endl;
  }
  return 0;
}
