#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #include <bits/stdc++.h> using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::pair;using std::set;using std::string;using std::vector; using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double; #define ff first #define ss second #define pb emplace_back template<typename T>void _dbg(const char*_s,T _h){cerr<<_s<<" = "<<_h<<"\n";} template<typename T,typename...Ts>void _dbg(const char*_s,T _h,Ts..._t){int _b=0;while(((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',')cerr<<*_s++;cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);} #ifdef LOCAL #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define dbg(...) #endif struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){ #ifdef LOCAL cerr<<"Time elaped: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n"; #endif }}init; const int N=1e6+1; int lp[N]; int pr[N]; int cpr = 0; void calc_primes(int n) { for (int i = 2; i <= n; ++i) { if (!lp[i]) { lp[i] = i; pr[cpr++] = i;; } for (int j = 0; j < cpr && pr[j] <= lp[i] && i * pr[j] <= n; ++j) lp[i * pr[j]] = pr[j]; } } const ll MOD = 1e9+7; ll binpow(ll a, ll pw) { ll res(1); for (; pw; a = (a * a) % MOD, pw /= 2, res %= MOD) res *= (pw & 1) * (a - 1) + 1; return res; } int a[N]; bool u[N]; bool w[N]; vector<int> g[N]; void dfs(int v){ u[v] = 1; for (int to : g[v]) { if (!u[to]) dfs(to); } } int main(){ calc_primes(N-1); int t; cin >> t; while(t--){ memset(u, 0, sizeof u); memset(w, 0, sizeof w); for (int i = 0; i < N; ++i) g[i].clear(); int n; cin >> n; int c = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; c += a[i] == 1; set<int> ps; while (a[i] != 1) { ps.insert(lp[a[i]]); a[i] /= lp[a[i]]; } for (int j : ps) { w[j] = 1; for (int k : ps) g[j].pb(k); } } for (int i = 1; i < N; ++i) { if (w[i]&&!u[i]) { dfs(i); c++; } } ll ans = (binpow(2, c) -2 + MOD) % MOD; cout << ans << '\n'; } return 0; }