#include <iostream>
#include <cstring>
using namespace std;
int f[1000001]={0};
long long solve (int a[], int n) {
long long res=0;
for (int i=0; i<n; i++) {
res+= ( (long long)f[a[i]] * (f[a[i]]-1) )/2;
// reset các tần suất của f[a[i]] lại =0 phòng việc xét nhiều lần 1 trường hợp
f[a[i]]=0;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--) {
int n; cin >> n;
int a[n];
for (int i=0; i<n; i++) cin >> a[i];
for (int i=0; i<n; i++) f[a[i]]++;
cout << solve (a, n) << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGZbMTAwMDAwMV09ezB9OwoKbG9uZyBsb25nIHNvbHZlIChpbnQgYVtdLCBpbnQgbikgewoJbG9uZyBsb25nIHJlcz0wOwoJZm9yIChpbnQgaT0wOyBpPG47IGkrKykgewoJCXJlcys9ICggKGxvbmcgbG9uZylmW2FbaV1dICogKGZbYVtpXV0tMSkgKS8yOwoJCS8vIHJlc2V0IGPDoWMgdOG6p24gc3XhuqV0IGPhu6dhIGZbYVtpXV0gbOG6oWkgPTAgcGjDsm5nIHZp4buHYyB4w6l0IG5oaeG7gXUgbOG6p24gMSB0csaw4budbmcgaOG7o3AgCgkJZlthW2ldXT0wOwoJfQoJcmV0dXJuIHJlczsKfQoKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0cik7CiAgICAKICAgIGludCB0OyBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pIHsKCSAgICBpbnQgbjsgY2luID4+IG47CgkgICAgaW50IGFbbl07IAoJICAgIGZvciAoaW50IGk9MDsgaTxuOyBpKyspIGNpbiA+PiBhW2ldOyAKCSAgICBmb3IgKGludCBpPTA7IGk8bjsgaSsrKQlmW2FbaV1dKys7CgkJY291dCA8PCBzb2x2ZSAoYSwgbikgPDwgZW5kbDsKCX0KfQ==