#include<stdio.h>
int main ()
{
int t;
long long int n,i,count,a,c;
scanf("%d",&t);
while(t>0)
{
scanf("%lld",&n);
i=0;count=0;c=0;
while(i<n)
{
scanf("%lld",&a);
if(a==2)
count++;
else if(a<2)
c++;
i++;
}
n-=c;
n=(n*(n-1)-count*(count-1))/2;
printf("%lld\n",n);
t--;
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KCmludCBtYWluICgpCnsKaW50ICB0Owpsb25nIGxvbmcgaW50IG4saSxjb3VudCxhLGM7CnNjYW5mKCIlZCIsJnQpOwp3aGlsZSh0PjApCnsKc2NhbmYoIiVsbGQiLCZuKTsKaT0wO2NvdW50PTA7Yz0wOwp3aGlsZShpPG4pCnsKc2NhbmYoIiVsbGQiLCZhKTsKaWYoYT09MikKY291bnQrKzsKZWxzZSBpZihhPDIpCmMrKzsKaSsrOwp9Cm4tPWM7Cm49KG4qKG4tMSktY291bnQqKGNvdW50LTEpKS8yOwpwcmludGYoIiVsbGRcbiIsbik7CnQtLTsKfQpyZXR1cm4gMDsKfQ==