#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int arr[n];
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n);
    if (n > 1) {
      arr[0] += k;
      arr[n - 1] -= k;
      if (arr[n - 1] <= arr[0])
        cout << arr[0] << '\n';
      else
        cout << -1 << '\n';
    } else {
      cout << arr[0] + k << '\n';
    }
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
