# Educational Codeforces Round 94 (Rated for Div. 2) D. Zigzags

#include<bits/stdc++.h>

using namespace std;

inline int rd(){
int ret=0,f=1;char c;
while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
while(isdigit(c))ret=ret*10+c-'0',c=getchar();
return ret*f;
}
#define pc putchar
#define space() pc(' ')
#define nextline() pc('\n')
void pot(int x){if(!x)return;pot(x/10);pc('0'+x%10);}
void out(int x){if(!x)pc('0');if(x<0)pc('-'),x=-x;pot(x);}

const int MAXN = 3005;

int n;
int a[MAXN];

int f[MAXN][MAXN];
int p[MAXN][MAXN];

void solve(){
memset(f,0,sizeof(f));
memset(p,0,sizeof(p));
n=rd();
for(int i=1;i<=n;i++) a[i]=rd();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) f[i][j]=f[i-1][j];
f[i][a[i]]++;
}
for(int i=n;i>=1;i--){
for(int j=1;j<=n;j++) p[i][j]=p[i+1][j];
p[i][a[i]]++;
}
long long ans=0;
for(int j=2;j<=n;j++){
for(int k=j+1;k<=n;k++){
ans+=1ll*p[k+1][a[j]]*f[j-1][a[k]];
}
}
cout<<ans<<endl;
}
int main(){
int T=rd();
while(T--) solve();
return 0;
}

posted @ 2020-08-26 22:06  GhostCai  阅读(76)  评论(1编辑  收藏  举报