/* chuckie */
#include <bits/stdc++.h>
//#include "/usr/local/include/bits/stdc++.h"
#define CHUCKIE
#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
const long long MOD = 1000000007 ;
const long long MOD2 = 1000000009 ;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODR(d) ((d)>=MOD?(d)%MOD:(d))
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;
#define MAX 1000000
#define ll long long
#define mp make_pair
#define pb push_back
#define pi acos(-1)
#define NIL -1
#define fi first
#define se second
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< string> vs;
typedef vector< ll> vll;
typedef pair< double ,double > dd;
typedef pair< int ,int > ii;
typedef pair< ll,ll> pll;
typedef vector< ii > vp;
typedef vector< vp > vvp;
ll arr[ 50005 ] ;
vector< pll > v;
ll rangesum[ 50005 ] ;
bool cmp( const pll & l, const pll & r)
{
return l.first < r.first ;
}
ll solve( int i,int l)
{
ll ans1= v[ i] .se * ( v[ i] .se - 1 ) / 2 ;
ll ans2= 0 ,ans3= 0 ;
for ( int j= 0 ; j< l; j++ )
{
ll mn= max( ( ll) 1 ,v[ j] .fi - 2 * v[ i] .fi + 1 ) ;
ll mx= 2 * v[ i] .fi + v[ j] .fi - 1 ;
ans3= 0 ;
//indexes
int li= lower_bound( v.begin ( ) ,v.end ( ) ,pll( mn,- 1 ) ,cmp) - v.begin ( ) ;
int ui= upper_bound( v.begin ( ) ,v.end ( ) ,pll( mx,- 1 ) ,cmp) - v.begin ( ) - 1 ;
if ( j== i) continue ;
if ( li>= l) continue ;
if ( ui< li) continue ;
//cout<<li<<" "<<ui<<"\n";
ans3= rangesum[ ui+ 1 ] - rangesum[ li] ;
//cout<<ans2<<"\n";
if ( j>= li && j<= ui) ans3- = ( v[ j] .se ) ;
if ( i>= li && i<= ui) ans3- = ( v[ i] .se ) ;
ans3* = v[ j] .se ;
//cout<<"ans3 "<<ans3<<" l "<<mn<<" \n";
ans2+ = ans3;
}
return ans1* ans2/ 2 ;
}
ll solve2( int i, int l)
{
ll ans1= v[ i] .se * ( v[ i] .se - 1 ) * ( v[ i] .se - 2 ) / 6 ;
ll ans2= 0 ;
int j= i;
ll mn= max( ( ll) 1 ,v[ j] .fi - 2 * v[ i] .fi + 1 ) ;
ll mx= 2 * v[ i] .fi + v[ j] .fi - 1 ;
//indexes
int li= lower_bound( v.begin ( ) ,v.end ( ) ,pll( mn,- 1 ) ,cmp) - v.begin ( ) ;
int ui= upper_bound( v.begin ( ) ,v.end ( ) ,pll( mx,- 1 ) ,cmp) - v.begin ( ) - 1 ;
if ( li>= l) return 0 ;
if ( ui>= l) ui= l- 1 ;
//cout<<li<<" "<<ui<<"\n";
ans2+ = rangesum[ ui+ 1 ] - rangesum[ li] ;
//cout<<ans2<<"\n";
if ( j>= li && j<= ui) ans2- = ( v[ j] .se ) ;
return ans1* ans2;
}
int main( )
{
#ifdef CHUCKIE
freopen ( "input.txt" ,"r" ,stdin ) ;
freopen ( "output.txt" ,"w" ,stdout ) ;
#endif
ios_base:: sync_with_stdio ( false ) ;
cin .tie ( NULL ) ;
///////////// code starts here ////////////////
int t,tc= 1 ;
cin >> t;
while ( t-- )
{
int n;
cin >> n;
v.clear ( ) ;
for ( int i= 0 ; i< n; i++ )
{
cin >> arr[ i] ;
}
sort( & arr[ 0 ] ,& arr[ 0 ] + n) ;
v.pb ( mp( arr[ 0 ] ,1 ) ) ;
int prev= arr[ 0 ] ;
for ( int i= 1 ; i< n; i++ )
{
if ( arr[ i] == prev)
{
v.back ( ) .se + = 1 ;
}
else
{
v.pb ( mp( arr[ i] ,1 ) ) ;
prev= arr[ i] ;
}
}
int l= v.size ( ) ;
rangesum[ 0 ] = 0 ;
for ( int i= 1 ; i<= l; i++ )
{
rangesum[ i] = rangesum[ i- 1 ] + v[ i- 1 ] .se ;
}
ll ans= 0 ,temp= 0 ;
for ( int i= 0 ; i< l; i++ )
{
temp= 0 ;
if ( v[ i] .se > 1 )
temp+ = solve( i,l) ;
if ( v[ i] .se > 2 )
temp+ = solve2( i,l) ;
//cout<<temp<<" ";
ans+ = temp;
}
cout << "Case #" << tc++ << ": " << ans<< "\n " ;
//cout<<t<<"\n";
}
return 0 ;
}
LyogIGNodWNraWUgICAqLwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KLy8jaW5jbHVkZSAiL3Vzci9sb2NhbC9pbmNsdWRlL2JpdHMvc3RkYysrLmgiCiNkZWZpbmUgQ0hVQ0tJRQogCiAKI2RlZmluZSBjaW50KGQpIHNjYW5mKCIlZCIsICZkKQojZGVmaW5lIGNpbnQyKGEsIGIpIHNjYW5mKCIlZCAlZCIsICZhLCAmYikKI2RlZmluZSBjaW50MyhhLCBiLCBjKSBzY2FuZigiJWQgJWQgJWQiLCAmYSwgJmIsICZjKQojZGVmaW5lIGNpbnQ0KGEsIGIsIGMsIGQpIHNjYW5mKCIlZCAlZCAlZCAlZCIsICZhLCAmYiwgJmMsICZkKQogCiNkZWZpbmUgY2xvbmcoZCkgc2NhbmYoIiVsbGQiLCAmZCkKI2RlZmluZSBjbG9uZzIoYSwgYikgc2NhbmYoIiVsbGQgJWxsZCIsICZhLCAmYikKI2RlZmluZSBjbG9uZzMoYSwgYiwgYykgc2NhbmYoIiVsbGQgJWxsZCAlbGxkIiwgJmEsICZiLCAmYykKI2RlZmluZSBjbG9uZzQoYSwgYiwgYywgZCkgc2NhbmYoIiVsbGQgJWxsZCAlbGxkICVs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