#include <bits/stdc++.h> using namespace std; const int md = (int) 1e9 + 7; class dsu { public: int n; vector<int> p; dsu(int n) : n(n) { p.resize(n); iota(p.begin(), p.end(), 0); } int get(int x) { return x == p[x] ? x : p[x] = get(p[x]); } inline bool unite(int x, int y) { x = get(x); y = get(y); if (x != y) { p[x] = y; return true; } return false; } int count() { int res = 0; for (int i = 0; i < n; ++i) { res += i == get(i); } return res; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); const int N = 1111111; vector<int> last(N); iota(last.begin(), last.end(), 0); for (int i = 2; i * i < N; ++i) { if (last[i] == i) { for (int j = i; j * i < N; ++j) { last[j * i] = i; } } } int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } dsu ds(n); map<int, int> mp; for (int i = 0; i < n; ++i) { int x = a[i]; while (x > 1) { int t = last[x]; if (mp.count(t)) { ds.unite(mp[t], i); } while (x % t == 0) { x /= t; } mp[t] = i; } } long long ans = 1; int sz = ds.count(); for (int i = 0; i < sz; ++i) { ans = (ans << 1) % md; } cout << ans - 2 << '\n'; } return 0; }