#include <bits/stdc++.h>
using namespace std;
const long long int L = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, k;
    cin >> n >> k;
    vector<long long int> a(n, 0);
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int ans = 0;
    long long int high = a[k] - a[0];
    long long int cur = high;
    long long int ind = 0;
    long long int at = 0;
    for (long long int i = k + 1; i < n; i++) {
      ind++;
      cur = a[i] - a[ind];
      if (high > cur) {
        at = ind;
      }
      high = min(high, cur);
    }
    cout << a[at] + high - high / 2 << "\n";
  }
  return 0;
}
