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: //Implemented By Aman Kotiyal Date:-10-Oct-2021  Time:-2:15:30 pm
  import java.io.*;
  import java.util.*;
  
  public class ques3
  {
  	public static void main(String[] args)throws Exception{ new ques3().run();} 
  	long mod=1000000000+7;
  	
  	void solve() throws Exception
  	{
  		for(int ii=ni();ii>0;ii--)
  		{
  			int n=ni();
  			long a[]=new long[n];
  			long sum=0;
  			HashMap<Long,Long> map= new HashMap<>();
  			for (int i = 0; i <n; i++) 
  				{
  				a[i]=nl();
  				sum+=a[i];
  				//map.put(a[i], map.getOrDefault(a[i], 0l)+1);
  				}
  			long ans=0;
  			double x=(double)(sum*2.0)/(double)n;
  			if(x-(long)(x)!=0) {
  				out.println("0");
  				continue;
  			}
  			long X=(long)x;
  			for (int i = 0; i <n; i++) 
  			{
  				ans+=map.getOrDefault(X-a[i],0l);
  				map.put(a[i], map.getOrDefault(a[i], 0l)+1);
  			}
  			out.println(ans);
  		}
  	}
  	
  	
  	/*FAST INPUT OUTPUT & METHODS BELOW*/
  	
  	private byte[] buf=new byte[1024];
  	private int index;
  	private InputStream in;
  	private int total;
  	private SpaceCharFilter filter;
  	PrintWriter out;
  	
  	int min(int... ar){int min=Integer.MAX_VALUE;for(int i:ar)min=Math.min(min, i);return min;}
  	long min(long... ar){long min=Long.MAX_VALUE;for(long i:ar)min=Math.min(min, i);return min;}
  	int max(int... ar) {int max=Integer.MIN_VALUE;for(int i:ar)max=Math.max(max, i);return max;}
  	long max(long... ar) {long max=Long.MIN_VALUE;for(long i:ar)max=Math.max(max, i);return max;}
  	void reverse(int a[]){for(int i=0;i<a.length>>1;i++){int tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}
  	void reverse(long a[]){for(int i=0;i<a.length>>1;i++){long tem=a[i];a[i]=a[a.length-1-i];a[a.length-1-i]=tem;}}
  	String reverse(String s){StringBuilder sb=new StringBuilder(s);sb.reverse();return sb.toString();}
  	
  	void shuffle(int a[]) {
  		ArrayList<Integer> al = new ArrayList<>();
  		for(int i=0;i<a.length;i++) 
  			al.add(a[i]);
  		
  		Collections.sort(al);
  		for(int i=0;i<a.length;i++) 
  			a[i]=al.get(i);
  	}
  	long lcm(long a,long b)
  	{
  		return (a*b)/(gcd(a,b));
  	}
  	
  	int gcd(int a, int b) 
  	{ 
  		if (a == 0) 
  			return b; 
  		return gcd(b%a, a); 
  	} 
  	long gcd(long a, long b) 
  	{ 
  		if (a == 0) 
  			return b; 
  		return gcd(b%a, a); 
  	}
  	/* for (1/a)%mod = ( a^(mod-2) )%mod  ----> use expo to calc -->(a^(mod-2)) */
  	long expo(long p,long q)  /*  (p^q)%mod   */
  	{
  		long z = 1;
  		while (q>0) {
  			if (q%2 == 1) {
  				z = (z * p)%mod;
  			}
  			p = (p*p)%mod;
  			q >>= 1;
  		}
  		return z;
  	}
  	void run()throws Exception
  	{
  		in=System.in; out = new PrintWriter(System.out);
  		solve();
  		out.flush();
  	}
  	private int scan()throws IOException
  	{
  		if(total<0)
  			throw new InputMismatchException();
  		if(index>=total)
  		{
  			index=0;
  			total=in.read(buf);
  			if(total<=0)
  				return -1;
  		}
  		return buf[index++];
  	}
  	private int ni() throws IOException 
  	{
  		int c = scan();
  		while (isSpaceChar(c))
  			c = scan();
  		int sgn = 1;
  		if (c == '-') {
  			sgn = -1;
  			c = scan();
  		}
  		int res = 0;
  		do {
  			if (c < '0' || c > '9')
  				throw new InputMismatchException();
  			res *= 10;
  			res += c - '0';
  			c = scan();
  		} while (!isSpaceChar(c));
  		return res * sgn;
  	}
  	private long nl() throws IOException 
  	{
  		long num = 0;
  		int b;
  		boolean minus = false;
  		while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
  			;
  		if (b == '-') {
  			minus = true;
  			b = scan();
  		}
  		
  		while (true) {
  			if (b >= '0' && b <= '9') {
  				num = num * 10 + (b - '0');
  			} else {
  				return minus ? -num : num;
  			}
  			b = scan();
  		}
  	}
  	private double nd() throws IOException{
  		return Double.parseDouble(ns());
  	}
  	private String ns() throws IOException {
  		int c = scan();
  		while (isSpaceChar(c))
  			c = scan();
  		StringBuilder res = new StringBuilder();
  		do {
  			if (Character.isValidCodePoint(c))
  				res.appendCodePoint(c);
  			c = scan();
  		} while (!isSpaceChar(c));
  		return res.toString();
  	}
  	private String nss() throws IOException
  	{
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		return br.readLine();
  	}
  	private char nc() throws IOException 
  	{
  		int c = scan();
  		while (isSpaceChar(c))
  			c = scan();
  		return (char) c;
  	}
  	private boolean isWhiteSpace(int n)
  	{
  		if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
  			return true;
  		return false;
  	}
  	private boolean isSpaceChar(int c) {
  		if (filter != null)
  			return filter.isSpaceChar(c);
  		return isWhiteSpace(c);
  	}
  	private interface SpaceCharFilter {
  		public boolean isSpaceChar(int ch);
  	}
  }