#include<bits/stdc++.h> using namespace std; const int MAX_N = 1e6 +121,N = 1e6; int pr[MAX_N],cnt,lp[MAX_N]; int n; int p[MAX_N]; bool used[MAX_N]; bool used2[MAX_N]; int f(int x){ if(x != p[x])return p[x] = f(p[x]); return p[x]; } int md = 1e9 + 7; int BinPow(int a,int b){ int ans = 1; while(b){ if(b & 1) ans = ans * 1ll * a % md; a = a * 1ll * a % md; b>>=1; } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); srand(time(NULL)); for(int i = 2; i <= N; ++i){ if(!lp[i]) pr[++cnt] = i, lp[i] = i; for(int j = 1; j <= cnt && pr[j] <= lp[i]; ++j){ long long val = pr[j] * 1ll * i; if(val > N)break; lp[val] = pr[j]; } } int t; cin >> t; while(t-->0){ cin >> n; for(int i = 1; i <= cnt; ++i) p[pr[i]] = pr[i],used[pr[i]] = 0,used2[pr[i]] = 0; int ans = 0; for(int i = 1; i <= n; ++i){ int a; cin >> a; if(a==1){ ++ans; continue; } used[lp[a]] = 1; int val = lp[a]; while(a>1){ val = f(val); used[lp[a]] = 1; int val2 = f(lp[a]); if(val != val2){ if(rand() % 2){ swap(val,val2); } p[val] = val2; } a/=lp[a]; } } for(int i = 1; i <= cnt; ++i){ if(used[pr[i]]){ int val = f(pr[i]); if(!used2[val]){ used2[val] = 1; ++ans; } } } //cout << ans << endl; cout << (BinPow(2,ans) - 2 + md) % md<< '\n'; } }