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: import java.util.*;
  import java.io.*;
  
  public class C {
  	static boolean multipleTC = true;
  	FastReader in;
  	PrintWriter out;
  
  	static int mod = 1000000007;
  
  	public static void main(String[] args) throws Exception {
  		new C().run();
  	}
  
  	void run() throws Exception {
  		in = new FastReader();
  		out = new PrintWriter(System.out);
  		int T = (multipleTC) ? ni() : 1;
  		pre();
  		for (int t = 1; t <= T; t++)
  			solve(t);
  		out.flush();
  		out.close();
  	}
  
  	void pre() throws Exception {
  	}
  
  	void solve(int TC) throws Exception {
  		int n = ni();
  		double arr[] = new double[n];
  		double sum = 0;
  		for (int i = 0; i < n; i++) {
  			arr[i] = ni();
  			sum += arr[i];
  		}
  		double mean = (sum / n);
  		double newSum = mean * (n - 2);
  		double req = sum - newSum;
  		long count = getPairsCount(n, req, arr);
  		pn(count);
  	}
  
  	static long getPairsCount(int n, double sum, double arr[]) {
  		HashMap<Double, Double> hm = new HashMap<>();
  		for (int i = 0; i < n; i++) {
  
  			if (!hm.containsKey(arr[i]))
  				hm.put(arr[i], (double)0);
  
  			hm.put(arr[i], hm.get(arr[i]) + 1);
  		}
  		long twice_count = 0;
  		for (int i = 0; i < n; i++) {
  			if (hm.get(sum - arr[i]) != null)
  				twice_count += hm.get(sum - arr[i]);
  			if (sum - arr[i] == arr[i])
  				twice_count--;
  		}
  		return twice_count / 2;
  	}
  
  	static int bitCount(int x) {
  		return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
  	}
  
  	static void dbg(Object... o) {
  		System.err.println(Arrays.deepToString(o));
  	}
  
  	public static boolean isPrime(long n) {
  		if (n < 2)
  			return false;
  		if (n == 2 || n == 3)
  			return true;
  		if (n % 2 == 0 || n % 3 == 0)
  			return false;
  		long sqrtN = (long) Math.sqrt(n) + 1;
  		for (long i = 6L; i <= sqrtN; i += 6) {
  			if (n % (i - 1) == 0 || n % (i + 1) == 0)
  				return false;
  		}
  		return true;
  	}
  
  	public static long gcd(long a, long b) {
  		if (a > b)
  			a = (a + b) - (b = a);
  		if (a == 0L)
  			return b;
  		return gcd(b % a, a);
  	}
  
  	public long pow(long base, long exp, long MOD) {
  		base %= MOD;
  		long res = 1;
  		while (exp > 0) {
  			if ((exp & 1) == 1)
  				res = res * base % MOD;
  			base = base * base % MOD;
  			exp >>= 1;
  		}
  		return res;
  	}
  
  	public static long totient(long n) {
  		long result = n;
  		for (int p = 2; p * p <= n; ++p)
  			if (n % p == 0) {
  				while (n % p == 0)
  					n /= p;
  				result -= result / p;
  			}
  		if (n > 1)
  			result -= result / n;
  		return result;
  	}
  
  	int bit(long n) {
  		return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
  	}
  
  	public long max(long... arr) {
  		long max = arr[0];
  		for (long itr : arr)
  			max = Math.max(max, itr);
  		return max;
  	}
  
  	public int max(int... arr) {
  		int max = arr[0];
  		for (int itr : arr)
  			max = Math.max(max, itr);
  		return max;
  	}
  
  	public long min(long... arr) {
  		long min = arr[0];
  		for (long itr : arr)
  			min = Math.min(min, itr);
  		return min;
  	}
  
  	public int min(int... arr) {
  		int min = arr[0];
  		for (int itr : arr)
  			min = Math.min(min, itr);
  		return min;
  	}
  
  	public long sum(long... arr) {
  		long sum = 0;
  		for (long itr : arr)
  			sum += itr;
  		return sum;
  	}
  
  	public long sum(int... arr) {
  		long sum = 0;
  		for (int itr : arr)
  			sum += itr;
  		return sum;
  	}
  
  	void p(Object o) {
  		out.print(o);
  	}
  
  	void pn(Object o) {
  		out.println(o);
  	}
  
  	void pni(Object o) {
  		out.println(o);
  		out.flush();
  	}
  
  	String n() throws Exception {
  		return in.next();
  	}
  
  	String nln() throws Exception {
  		return in.nextLine();
  	}
  
  	int ni() throws Exception {
  		return Integer.parseInt(in.next());
  	}
  
  	long nl() throws Exception {
  		return Long.parseLong(in.next());
  	}
  
  	double nd() throws Exception {
  		return Double.parseDouble(in.next());
  	}
  
  	class FastReader {
  		BufferedReader br;
  		StringTokenizer st;
  
  		public FastReader() {
  			br = new BufferedReader(new InputStreamReader(System.in));
  		}
  
  		public FastReader(String s) throws Exception {
  			br = new BufferedReader(new FileReader(s));
  		}
  
  		String next() throws Exception {
  			while (st == null || !st.hasMoreElements()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					throw new Exception(e.toString());
  				}
  			}
  			return st.nextToken();
  		}
  
  		String nextLine() throws Exception {
  			String str = "";
  			try {
  				str = br.readLine();
  			} catch (IOException e) {
  				throw new Exception(e.toString());
  			}
  			return str;
  		}
  	}
  }