#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define oo 666666666

int Find(vector<int>&P, int u)
{
    return P[u]<0 ? u : P[u]=Find(P,P[u]);
}

void Union(vector<int>&P, int u, int v)
{
    u = Find(P,u);
    v = Find(P,v);
    if(u==v)return;
    P[u]+=P[v];
    P[v]=u;
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    vector<int>SPF(1000001);
    for(int i=1; i<1000001; i++)SPF[i]=i;
    for(int i=2; i*i<1000001; i++)
        if(SPF[i]==i)
        for(int j=2*i; j<1000001; j+=i)
        if(SPF[j]==j)SPF[j]=i;

    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<int>P(1000001,-1);
        bitset<1000001>in(0);
        int ones = 0;

        for(int i=1; i<=n; i++)
        {
            int x;
            cin>>x;
            if(x==1)ones++;
            set<int>D;
            while(x!=1)
                in[SPF[x]]=1,D.insert(SPF[x]),x/=SPF[x];

            for(auto u : D)
            for(auto v : D)
            Union(P,u,v);
        }

        int cnt = ones;
        for(int i=2; i<1000001; i++)
        if(in[i] && P[i] < 0)cnt++;

        ll ats = (cnt==1 ? 0 : 1);
        ll M = 1e9+7;

        for(int i=1; i<=cnt; i++)
            ats = (ats*2)%M;

        if(cnt==1)cout<<"0\n";
        else
        cout<<(ats-2+M)%M<<"\n";
    }
}