public class Main
{
public static void main(String[] args) {
int[] a={1,2,3,5,5,8,2,0,5,4};
int i,j,count=0;
for(i=0;i<a.length-1;i++)
{
 for(j=i+1;j<a.length;j++)
 {
   if(a[i]+a[j]==9)
   count++;
 }
}
System.out.println(count);

}
}

Given an array of distinct integers. The task is to count all the triplets such that sum of two elements equals the third element.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting size of array and the second line contains N space separated elements.
Output:
For each test case, print the count of all triplets, in new line. If no such triplets can form, print "-1".
Example:
Input:

2
4
1 5 3 2
3
3 2 7
Output:
2
-1
Explanation:
Testcase 1:
 There are 2 triplets: 1 + 2 = 3 and 3 +2 = 5