#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
int t, n, masti[N], ap[1 << 17];
vector<int>v;
bool good (int x)
{
for(int i = 2; i * i <= x; i ++)
if(x % i == 0) return 0;
return x != 1;
}
void getPr ()
{
for(int i = 2; i <= 47; i++)
if(good(i))
v.push_back(i);
}
template < class T>
T readInt () {
bool minus = false;
T result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true; else result = ch-'0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result*10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
void solve ()
{
memset(ap, 0, sizeof(ap));
scanf("%d", &n);
for(int i = 1 ; i <= n ; i++)
{
int mask = 0;long long x;
scanf("%lld", &x);
for(int j = 0; j < 15; j++)
if(x % v[j] == 0)
mask |= 1 << j;
++ap[mask];
}
long long ans = 0, cans;
int nr = (1 << 15) - 1, sz = 0;
for(int i = 0; i < (1 << 16); i++)
for(int j=1;j<=ap[i];j++)masti[sz++]=i;
for(int s=0;s<sz;s++)
{
int val = masti[s];
int opus = (~val) & nr;
cans = 0;
for(int cur = opus; ; cur = (cur - 1) & opus)
{
cans += ap[cur];
for(int j = val; j ; j -= j & -j)
cans += ap[cur | (j & -j)];
if(cur == 0) break;
}
int nrn = 1;
while(s + 1 < sz && masti[s+1] == masti[s]) s++, nrn++;
ans += cans * nrn;
}
printf("%lld\n", ans);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.in","r",stdin);
#endif
getPr ();srand(time(0));
scanf("%d", &t);
while(t--)
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAxMDAwMDk7CgppbnQgdCwgbiwgbWFzdGlbTl0sIGFwWzEgPDwgMTddOwp2ZWN0b3I8aW50PnY7Cgpib29sIGdvb2QgKGludCB4KQp7CiAgIG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IHw9IDEgPDwgajsKICAgICAgKythcFttYXNrXTsKICAgfQoKICAgbG9uZyBsb25nIGFucyA9IDAsIGNhbnM7CiAgIGludCBuciA9ICgxIDw8IDE1KSAtIDEsIHN6ID0gMDsKCiAgIGZvcihpbnQgaSA9IDA7IGkgPCAoMSA8PCAxNik7IGkrKykKICAgICAgZm9yKGludCBqPTE7ajw9YXBbaV07aisrKW1hc3RpW3N6KytdPWk7CgogICBmb3IoaW50IHM9MDtzPHN6O3MrKykKICAgewogICAgICBpbnQgdmFsID0gbWFzdGlbc107CiAgICAgIGludCBvcHVzID0gKH52YWwpICYgbnI7CiAgICAgIGNhbnMgPSAwOwogICAgICBmb3IoaW50IGN1ciA9IG9wdXM7IDsgY3VyID0gKGN1ciAtIDEpICYgb3B1cykKICAgICAgewogICAgICAgICBjYW5zICs9IGFwW2N1cl07CiAgICAgICAgIGZvcihpbnQgaiA9IHZhbDsgaiA7IGogLT0gaiAmIC1qKQogICAgICAgICAgIGNhbnMgKz0gYXBbY3VyIHwgKGogJiAtaildOwogICAgICAgICBpZihjdXIgPT0gMCkgYnJlYWs7CiAgICAgIH0KCiAgICAgIGludCBucm4gPSAxOwogICAgICB3aGlsZShzICsgMSA8IHN6ICYmIG1hc3RpW3MrMV0gPT0gbWFzdGlbc10pIHMrKywgbnJuKys7CiAgICAgIGFucyArPSBjYW5zICogbnJuOwogICB9CgogICBwcmludGYoIiVsbGRcbiIsIGFucyk7Cn0KCmludCBtYWluKCkKewogICAjaWZuZGVmIE9OTElORV9KVURHRQogICBmcmVvcGVuKCJkYXRhLmluIiwiciIsc3RkaW4pOwogICAjZW5kaWYKICAgZ2V0UHIgKCk7c3JhbmQodGltZSgwKSk7CiAgIHNjYW5mKCIlZCIsICZ0KTsKICAgd2hpbGUodC0tKQogICBzb2x2ZSgpOwogICAgICByZXR1cm4gMDsKfQo=