#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct tuple {
  ll x;
  ll y;
  ll z;
};
ll inf = LONG_MAX;
ll cei(ll x, ll y) {
  ll t = (x + y - 1) / y;
  return t;
}
ll power(ll base, ll powerRaised) {
  if (powerRaised != 0)
    return (base * power(base, powerRaised - 1));
  else
    return 1;
}
ll findTheStriclyLessPower(ll base, ll n) {
  if (n == 1) {
    return 0;
  }
  ll temp = log(n) / log(base);
  if (power(base, temp) == n) {
    return temp - 1;
  } else {
    return temp;
  }
}
ll gcd(ll x, ll y) {
  ll ans = x;
  ll temp = y;
  while (ans != temp) {
    if (ans < temp) {
      temp -= ans;
    } else {
      ans -= temp;
    }
  }
  return ans;
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
void solve() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  multiset<ll> second;
  set<ll> s1;
  map<ll, ll> m;
  for (ll i = 0; i < ll(n); i++) {
    cin >> a[i];
    sum += a[i];
    second.insert(a[i]);
    s1.insert(a[i]);
    if (m.find(a[i]) == m.end()) {
      m[a[i]] = 1;
    } else {
      m[a[i]]++;
    }
  }
  if ((2 * sum) % n != 0) {
    cout << 0 << endl;
    return;
  } else {
    ll res = 2 * sum / n;
    ll ans = 0;
    for (ll x : s1) {
      if (res >= x) {
        if (res - x == x) {
          ans += m[x] * (m[x] - 1);
        } else if (m.find(res - x) != m.end()) {
          ans += m[x] * m[res - x];
        }
      }
    }
    cout << ans / 2 << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int c;
  cin >> c;
  while (c--) {
    solve();
  }
}
