#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int T,N;
int A[1010101];

template<int um> class UF {
    public:
    vector<int> par,rank,cnt;
    UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
    void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
    int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
    int count(int x) { return cnt[operator[](x)];}
    int operator()(int x,int y) {
        if((x=operator[](x))==(y=operator[](y))) return x;
        cnt[y]=cnt[x]=cnt[x]+cnt[y];
        if(rank[x]>rank[y]) return par[x]=y;
        rank[x]+=rank[x]==rank[y]; return par[y]=x;
    }
};

const int prime_max = 1100000;
int NP,prime[1000000],divp[prime_max];

void cprime() {
    if(NP) return;
    for(int i=2;i<prime_max;i++) if(divp[i]==0) {
        prime[NP++]=i;
        for(ll j=1LL*i*i;j>=i&&j<prime_max;j+=i) if(divp[j]==0) divp[j]=i;
    }
}

UF<1<<20> uf;
ll mo=1000000007;

void solve() {
    int i,j,k,l,r,x,y; string s;
    
    cprime();
    cin>>T;
    while(T--) {
        cin>>N;
        ZERO(A);
        uf.reinit();
        FOR(i,N) cin>>x, A[x]++;
        FOR(i,NP) {
            x=prime[i];
            y=0;
            for(j=x;j<=1000000;j+=x) if(A[j]) {
                if(y) uf(y,j);
                y=j;
            }
        }
        ll ret=1;
        for(i=2;i<=1000000;i++) if(A[i]&&uf[i]==i) ret=ret*2%mo;
        FOR(i,A[1]) ret=ret*2%mo;
        ret=(ret+mo-2)%mo;
        cout<<ret<<endl;
        
        
        
    }
}


int main(int argc,char** argv){
    string s;int i;
    if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
    FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
    cout.tie(0); solve(); return 0;
}