description: Monocarp has got an array a consisting of n integers. Let's denote k as the mathematic mean of these elements (note that it's possible that k is not an integer). 
  
  The mathematic mean of an array of n elements is the sum of elements divided by the number of these elements (i. e. sum divided by n).
  
  Monocarp wants to delete exactly two elements from a so that the mathematic mean of the remaining (n - 2) elements is still equal to k.
  
  Your task is to calculate the number of pairs of positions [i, j] (i < j) such that if the elements on these positions are deleted, the mathematic mean of (n - 2) remaining elements is equal to k (that is, it is equal to the mathematic mean of n elements of the original array a).
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of testcases.
  
  The first line of each testcase contains one integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in the array.
  
  The second line contains a sequence of integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{9}), where a_i is the i-th element of the array.
  
  The sum of n over all testcases doesn't exceed 2 ⋅ 10^5.
  
  Output
  
  Print one integer — the number of pairs of positions [i, j] (i < j) such that if the elements on these positions are deleted, the mathematic mean of (n - 2) remaining elements is equal to k (that is, it is equal to the mathematic mean of n elements of the original array a).
  
  Example
  
  Input
  
  
  4
  4
  8 8 8 8
  3
  50 20 10
  5
  1 4 7 3 5
  7
  1 2 3 4 5 6 7
  
  
  Output
  
  
  6
  0
  2
  3
  
  Note
  
  In the first example, any pair of elements can be removed since all of them are equal.
  
  In the second example, there is no way to delete two elements so the mathematic mean doesn't change.
  
  In the third example, it is possible to delete the elements on positions 1 and 3, or the elements on positions 4 and 5.
solution: #include <bits/stdc++.h>
  using namespace std;
  int mod = 1000000007;
  long long add(long long a, long long b) {
    long long res = a + b;
    if (res >= mod) res -= mod;
    return res;
  }
  long long sub(long long a, long long b) {
    long long res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
  }
  long long mul(long long a, long long b) {
    return (((a % mod) * (b % mod)) % mod);
  }
  long long potolok(long long a, long long b) { return (a + b - 1) / b; }
  long long gcd(long long x, long long y) {
    if (y == 0) {
      return x;
    }
    if (x == 0) {
      return y;
    }
    if (x > y) {
      return gcd(y, x % y);
    } else {
      return gcd(x, y % x);
    }
  }
  struct segtree {
    int razmer;
    vector<long long> tree;
    void Init(vector<long long> &v) {
      int n = (int)v.size();
      razmer = 1;
      while (razmer < n) razmer *= 2;
      tree.assign(2 * razmer - 1, 0);
    }
    void build(vector<long long> &v, int x, int lx, int rx) {
      if (rx - lx == 1) {
        if (lx < (int)v.size()) {
          tree[x] = v[lx];
        }
      } else {
        int m = (lx + rx) / 2;
        build(v, 2 * x + 1, lx, m);
        build(v, 2 * x + 2, m, rx);
        tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]);
      }
    }
    void build(vector<long long> &v) { build(v, 0, 0, razmer); }
    void cet(int i, int v, int x, int lx, int rx) {
      if (rx - lx == 1) {
        tree[x] = v;
        return;
      } else {
        int m = (lx + rx) / 2;
        if (i < m) {
          cet(i, v, 2 * x + 1, lx, m);
        } else {
          cet(i, v, 2 * x + 2, m, rx);
        }
        tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]);
      }
    }
    void cet(int i, int v) { cet(i, v, 0, 0, razmer); }
    long long mn(int l, int r, int x, int lx, int rx) {
      if (lx >= r || l >= rx) {
        return mod;
      }
      if (lx >= l && rx <= r) {
        return tree[x];
      } else if (min(rx, r) - max(lx, l) >= 0) {
        int m = (lx + rx) / 2;
        long long s1 = mn(l, r, 2 * x + 1, lx, m);
        long long s2 = mn(l, r, 2 * x + 2, m, rx);
        return min(s1, s2);
      }
    }
    long long mn(int l, int r) { return mn(l, r, 0, 0, razmer); }
  };
  bool isSquare(int x) {
    int y = (int)(sqrt(x));
    while (y * y < x) y++;
    while (y * y > x) y--;
    return y * y == x;
  }
  void solve() {
    int n;
    cin >> n;
    vector<long long> v(n);
    map<long long, long long> mp;
    long long ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      sum += v[i];
      mp[v[i] * n]++;
    }
    sum *= 2;
    for (int i = 0; i < n; i++) {
      if (mp.count(sum - v[i] * n)) {
        if (sum - v[i] * n == v[i] * n) {
          ans += (mp[sum - v[i] * n] - 1);
        } else {
          ans += mp[sum - v[i] * n];
        }
      }
    }
    cout << ans / 2 << endl;
  }
  int main() {
    int t;
    cin >> t;
    while (t--) {
      solve();
    }
    return 0;
  }
  