#include <bits/stdc++.h>
using namespace std;
void print_width(long long x) {
  std::cout << std::fixed;
  std::cout << std::setprecision(x);
}
long long power(long long x, long long y, long long p = 1000000007) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void printArr(long long a[], long long n) {
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  cout << endl;
}
void printVector(std::vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
long long Min(long long a, long long b, long long c) {
  if (a < b and a < c) return a;
  if (b < c) return b;
  return c;
}
void initialize(long long arr[], long long n) {
  for (long long i = 0; i <= n; i++) arr[i] = i;
}
long long root(long long arr[], long long i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void Union(long long arr[], long long a, long long b) {
  long long root_a = root(arr, a);
  long long root_b = root(arr, b);
  arr[root_a] = root_b;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power_wm(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long double dpower(long double x, long long y) {
  long double res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
std::vector<long long> vsum(std::vector<long long> a) {
  std::vector<long long> s(a.size());
  s[0] = a[0];
  for (long long i = 1; i <= a.size() - 1; i++) {
    s[i] = s[i - 1] + a[i];
  }
  return s;
}
int h[100001] = {0};
long long d[100001] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long l;
  cin >> l;
  while (l--) {
    long long n, k;
    cin >> n >> k;
    std::vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ;
    long long t = k + 1;
    long long x = 1;
    long long d = 99999999999999999;
    for (long long i = 0; i <= n - t; i++) {
      long long a1 = a[i];
      long long a2 = a[i + k];
      if ((a2 - a1) < d) {
        d = a2 - a1;
        x = (a2 + a1) / 2;
      }
    }
    cout << x << endl;
  }
  return 0;
}
