Problem: Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.

Can you help Heidi estimate each village's population?

Input

Same as the easy version.

Output

Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.

Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
long double pi = 3.1415926535897932384626433832795;
long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long _gcd(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long _x1, _y1;
  long long d = _gcd(b % a, a, _x1, _y1);
  x = _y1 - (b / a) * _x1;
  y = _x1;
  return d;
}
long double binpow(long double a, long long n) {
  long double res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
const int N = 5e5 + 10;
vector<pair<int, int> > g[N];
int a[555];
int b[11];
void solve() {
  int n = 250;
  int mx = 0;
  for (int i = 0; i < n; i++) cin >> a[i], mx = max(a[i], mx);
  memset(b, 0, sizeof(b));
  long double m = 0;
  for (int i = 0; i < n; i++) {
    b[a[i] / (mx / 10)]++;
    m += a[i];
  }
  m /= n;
  long double d_p = m;
  long double d_r = (long double)mx * mx / 12;
  long double real_d = 0;
  for (int i = 0; i < n; i++) {
    real_d += sqr((long double)a[i] - m);
  }
  real_d /= (n - 1);
  if (abs(d_p - real_d) < abs(d_r - real_d)) {
    cout << (int)m;
  } else {
    cout << (int)((mx) / 2);
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}