#include<bits/stdc++.h> #define N 1000005 using namespace std; int prime[N],flag[N],f[N],cur[N],Time[N]; int n,Case,cnt; const int P=1000000007; int get(int u){return f[u]==u?u:f[u]=get(f[u]);} void Insert(int x,int ID){ if (Time[x]==Case) f[get(cur[x])]=get(ID); cur[x]=ID;Time[x]=Case; } int main(){ n=1e6; for (int i=2;i<=n;i++){ if (!flag[i]) prime[++cnt]=i,flag[i]=i; for (int j=1;j<=cnt&&prime[j]*i<=n;j++){ flag[prime[j]*i]=prime[j]; if (i%prime[j]==0) break; } } int T;scanf("%d",&T); while (T--){ scanf("%d",&n); for (int i=1;i<=n;i++) f[i]=i; ++Case; for (int i=1;i<=n;i++){ int x; scanf("%d",&x); for (;x>1;x/=flag[x]) Insert(flag[x],i); } int tot=0,ans=1; for (int i=1;i<=n;i++) tot+=get(i)==i; for (int i=1;i<=tot;i++) ans=ans*2%P; printf("%d\n",(ans-2+P)%P); } }