#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5, A = 1e6 + 5, mod = 1e9 + 7; int t, n, bp[A], pset[N], numset, group[A]; int findset(int i) { return i == pset[i] ? i : pset[i] = findset(pset[i]); } bool sameset(int i, int j) { return findset(i) == findset(j); } void disjointset(int i, int j) { if(!sameset(i, j) ) { numset --; pset[findset(i)] = findset(j); } } int fpow(int _a, int _m) { int res = 1; for (; _m; _m >>= 1, _a = (1LL * _a * _a) % mod) if(_m & 1) res = (1LL * res * _a) % mod; return res; } void EntityIT() { cin >> n; for (int i = 1; i <= n; ++i) pset[i] = i; numset = n; memset(group, -1, sizeof group); for (int i = 1; i <= n; ++i) { int a; cin >> a; while(bp[a] != 1) { if(group[ bp[a] ] == -1) { group[ bp[a] ] = i; } else disjointset(group[ bp[a] ], i); int now = bp[a]; while(a % now == 0) a /= now; } } cout << (fpow(2, numset) - 2 + mod) % mod << '\n'; } void sieve() { bp[1] = 1; for (int i = 2; i < A; ++i) { if(bp[i]) continue; for (int j = i; j < A; j += i) bp[j] = i; } } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); sieve(); cin >> t; while(t--) EntityIT(); return 0; }