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: //package contests;
  
  import static java.lang.Math.max;
  import static java.lang.Math.min;
  import static java.lang.Math.abs;
  import static java.lang.System.out;
  import java.util.* ;
  import java.math.*;
  import java.io.*;
  
  public class javaTemplate {
  	
  	public static final int M = 1000000007 ;
  	public static BigInteger f1 = new BigInteger("1000000007") ;
  	static FastReader sc = new FastReader();
  	static int N = 86028121 ;
  	static boolean globB[] = new boolean[N+1] ;
  	static int globA[] = new int[10000000] ;
  
  	public static void main(String[] args) {
  	
  		int t = sc.nextInt() ;
  		
  		while(t -- != 0) {
  			long n = sc.nextLong() ;
  			long a[] = new long[(int)n] ;
  			HashMap<Long,Long> map = new HashMap<>() ;
  			long sum = 0 ;
  			for(int i = 0 ; i< a.length ; i++) {
  				a[i] = sc.nextLong() ;
  				sum += a[i] ;
  			}
  			
  			
  			if((2*sum) % n != 0) {
  				System.out.println("0");
  			} else {
  				long x = (2*sum) / n ;
  				long ans = 0 ;
  				for(int i = 0 ; i< n ; i ++) {
  					if(map.containsKey((x-a[i]))) {
  						ans += map.get((x-a[i])) ;
  					} 
  					map.put(a[i], (map.containsKey(a[i])?map.get(a[i])+1:1));
  				}
  				System.out.println(ans);
  			}
  			
  		}
  		
  		
  		
  	}
  	
  	
  	
  	 
  	/*
  	 @ Observation is imp. for problem A and B
  	 1->> Read the problem properly take time to read the problem 
  	 if it is too lengthy.
  	 2->> Draw the test cases of A and B 
  	 3->> Don't over think the problem 
  	 4->> Try to take sum variable as long
  	 5->> Avoid Nested if else statement
  	 6->> If it looks like a Greedy problem try to figure out the ans. 
  	 for the smallest test case.
  	 7->> If it is a binary String check no. of 0's and 1's. 
  	 If it is a even try to pair it (may be not applicable for every questions).
  	 8->> Always check the constrains and try BruteForce
  	 9->> Sometimes math formulas are also imp.
  	 @ Implement it quickly 
  	 */
  	
  	
  
  
  	
  
  	
  	
  	//_________________________//Template//_____________________________________________________________________
  	
  	
  			//		FAST I/O
  			static class FastReader {
  		        BufferedReader br;
  		        StringTokenizer st;
  		        
  		        public FastReader()
  		        {
  		            br = new BufferedReader(
  		                new InputStreamReader(System.in));
  		        }
  		 
  		        String next()
  		        {
  		            while (st == null || !st.hasMoreElements()) {
  		                try {
  		                    st = new StringTokenizer(br.readLine());
  		                }
  		                catch (IOException e) {
  		                    e.printStackTrace();
  		                }
  		            }
  		            return st.nextToken();
  		        }
  		 
  		        int nextInt() { return Integer.parseInt(next()); }
  		 
  		        long nextLong() { return Long.parseLong(next()); }
  		 
  		        double nextDouble()
  		        {
  		            return Double.parseDouble(next());
  		        }
  		 
  		        String nextLine()
  		        {
  		            String str = "";
  		            try {
  		                str = br.readLine();
  		            }
  		            catch (IOException e) {
  		                e.printStackTrace();
  		            }
  		            return str;
  		        }
  			}
  		
  		
  			
  			
  			
  			// Sorting
  			public static void sort(long[] arr) {
  		        ArrayList<Long> ls = new ArrayList<Long>();
  		        for(long x: arr)
  		            ls.add(x);
  		        Collections.sort(ls);
  		        for(int i=0; i < arr.length; i++)
  		            arr[i] = ls.get(i);
  		    }
  			
  			
  			
  			
  			
  			// Modulo
  			static int mod(int a) {
  			   return (a%M+M)%M;
  			}
  			
  			
  			
  			
  			
  			
  			
  			//		Palindrom or Not
  			static boolean isPalindrome(String str, int low, int high) {
  						while (low < high) {
  							if (str.charAt(low) != str.charAt(high)) return false;
  						 	low++;
  						 	high--;
  						}
  						return true;
  					}
  		
  		
  
  		
  		
  		
  		
  		
  		
  		
  		
  			// check if sorted or not	
  			public static boolean isSorted(int[] a)
  		    {
  		        for (int i = 0; i < a.length - 1; i++)
  		        {
  		            if (a[i] > a[i + 1]) {
  		                return false;
  		            }
  		        }
  		        return true;
  		    }
  		
  		
  		
  			
  			
  		
  			// GCD
  			public static int GCD(int a , int b) {
  					if(b == 0) return a ;
  					
  					return GCD(b, a%b) ;
  				}
  		
  			
  			
  			
  			
  			// sieve
  			public static void sieve() {
  				Arrays.fill(globB, true);
  				globB[0] = false ;
  				globB[1] = false ;
  				for(int i = 2 ; i * i <= N ; i++) {
  					if(globB[i]) {
  					for(int j = i * i ; j<= N ; j+= i) {
  						globB[j] = false ;
  					 }
  					}
  				}
  				
  			}
  
  			
  			
  			
  			// fastPower
  			public static long fastPowerModulo(long a, long b, long n) {
  				long res = 1 ;
  				while(b > 0) {
  				if((b&1) != 0) {
  					res = (res * a % n) % n ;
  				}
  				a = (a % n * a % n) % n ;
  				b = b >> 1 ;
  				}
  				return res ;
  			}
  		
  			
  			
  	        // LCM
  			static int LCM(int a, int b)
  		    {
  		        return (a / GCD(a, b)) * b;
  		    }
  			
  
  	}
  
  
  