#include <bits/stdc++.h>
using namespace std;
int n[101];
int ans[105];
int main() {
  int q;
  cin >> q;
  int N, K;
  int k = 0;
  for (int i = 0; i < q; i++) {
    cin >> N;
    cin >> K;
    for (int i = 0; i < N; i++) cin >> n[i];
    sort(n, n + N);
    if (n[0] + K + K >= n[N - 1])
      ans[k++] = n[0] + K;
    else
      ans[k++] = -1;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
