#include <bits/stdc++.h>
using namespace std;
inline void fileio(const char* in, const char* out) {
  freopen(in, "r", stdin);
  freopen(out, "w", stdout);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<ll> VL;
const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld EPS = 1e-9, PI = acos(-1);
void deal(int T) {
  int n, k;
  cin >> n >> k;
  VI nums(n);
  for (int i = 0; i < (n); ++i) {
    cin >> nums[i];
  }
  ll best = INT_MAX;
  ll x;
  for (int i = 0, j = k; j < n; ++i, ++j) {
    ll _x = nums[i] + nums[j] >> 1;
    ll dist = max(_x - nums[i], nums[j] - _x);
    if (dist < best) {
      best = dist;
      x = _x;
    }
  }
  cout << x << nl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  for (int i = 0; i < (T); ++i) deal(i);
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}
