#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int a[maxn], vis[maxn];
int main() {
  long long i, x, y, k, n, d, j, t, z, m, w,
      overflow = 0, ans = 0, minn = 0, mi = 0, ma = 0, maxx = 0, temp1 = 0,
      temp2 = 0, temp = 0, sum = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0,
      flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0, flag = 0, len2 = 0, len1 = 0,
      len = 0;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    long long x, arr[n + 1];
    for (i = 0; i < n; i++) cin >> arr[i];
    if (k == 0) {
      cout << arr[0] << '\n';
      continue;
    }
    minn = INT_MAX;
    for (i = 0; i < n - k; i++) {
      if (arr[i + k] - arr[i] < minn) {
        minn = arr[i + k] - arr[i];
        x = (arr[i + k] + arr[i]) / 2;
      }
    }
    cout << x << '\n';
  }
  return 0;
}
