// TEMPLATE - START
// ----------------------------------------------------
using namespace std;
// ----------------------------------------------------
// DEFINES - START
#include <bits/stdc++.h>
#define FAST                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
// Strings
#define nl "\n"
#define bl cout << "\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define yn(x) \
    if (x)    \
        YES;  \
    else      \
        NO;
#define yns(x, s1, s2)      \
    if (x)                  \
        cout << s1 << "\n"; \
    else                    \
        cout << s2 << "\n";
#define fail(cond) \
    if (cond)      \
        return void(NO);
#define success(cond) \
    if (cond)         \
        return void(YES);
#define failS(cond, s) \
    if (cond)          \
        return void(cout << s << nl);
#define successS(cond, s) \
    if (cond)             \
        return void(cout << s << nl);
// Types
#define ll long long
#define ld long double
#define ull unsigned long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// Loops
#define lp(i, a, b) for (int i = (a); i < (b); i++)
#define rlp(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define readlp(arr, a, b) \
    lp(ind, a, b) cin >> arr[ind];
#define writelp(arr, a, b)                     \
    {                                          \
        lp(ind, a, b) cout << arr[ind] << " "; \
        bl;                                    \
    }
#define write(v)              \
    {                         \
        for (auto x : v)      \
            cout << x << " "; \
        bl;                   \
    }
#define vv    \
    ll n;     \
    cin >> n; \
    vl v(n);  \
    readlp(v, 0, v.size());
// DEFINES - END
// ----------------------------------------------------
// DATA_STRUCTURES - START
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

// Ordered set (no duplicates, ordered by Key)
template <class Key>
using ordered_set = tree<Key, null_type, less<Key>, rb_tree_tag, tree_order_statistics_node_update>;

// Ordered multi-set (allows duplicates, ordered by Key)
template <class Key>
using ordered_multi_set = tree<Key, null_type, less_equal<Key>, rb_tree_tag, tree_order_statistics_node_update>;

// Ordered map (Key -> Value, ordered by Key)
template <class Key, class Val>
using ordered_map = tree<Key, Val, less<Key>, rb_tree_tag, tree_order_statistics_node_update>;
// DATA_STRUCTURES - END
// ----------------------------------------------------
// ALGORITHMS - START
// Binary Search Custom:
// To Find...,Logical Condition,If Condition is Met...,Return Value
// Lower Bound (First element ≥x),arr[m] >= x,r = m,r
// Upper Bound (First element >x),arr[m] > x,r = m,r
// Last element <x,arr[m] < x,l = m,l
// Last element ≤x,arr[m] <= x,l = m,l

ll lowerBound(vector<ll> &v, ll x)
{
    ll l = -1, r = v.size();
    while (r > l + 1)
    {
        ll m = l + (r - l) / 2;
        if (v[m] >= x)
            r = m;
        else
            l = m;
    }
    return r;
}
// ALGORITHMS - END
// ----------------------------------------------------
// TEMPLATE END

// ====================================================

// Boody's Code
// 2026-10-07, 19:48:34
// Codeforces - Codeforces Round 1125 (Div. 3)
// F. Tea Blend
// https://c...content-available-to-author-only...s.com/contest/2275/problem/F
// Time limit: 00, Memory limit: 5
// status:
// Time taken:

// ----------------------------------------------------

set<ll> primeFactors(ll x)
{
    map<ll, ll> factors;
    set<ll> oddFactors;
    while (x % 2 == 0)
        factors[2]++, x = x / 2;
    for (ll i = 3; i * i <= x; i = i + 2)
        while (x % i == 0)
            factors[i]++, x = x / i;
    if (x > 2)
        factors[x]++;

    oddFactors.insert(0);
    for (auto [key, val] : factors)
        if (val & 1)
            oddFactors.insert(key);

    return oddFactors;
}

void solve()
{
    ll n;
    cin >> n;
    vl v(n);
    readlp(v, 0, v.size());
    map<set<ll>, ll> frq;
    lp(i, 0, n) frq[primeFactors(v[i])]++;

    set<ll> currOdd;
    currOdd.insert(0);
    ll ans = 0;
    lp(i, 0, n)
    {
        for (auto x : primeFactors(v[i]))
        {
            if (!x)
                continue;
            if (currOdd.find(x) != currOdd.end())
                currOdd.erase(x);
            else
                currOdd.insert(x);
        }
        if (frq.find(currOdd) != frq.end())
            ans += frq[currOdd];
    }
    cout << ans << nl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("/home/rodex/rubuntu/CS/CP/input.txt", "r", stdin);
    freopen("/home/rodex/rubuntu/CS/CP/output.txt", "w", stdout);
#endif
    FAST;
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}