/** * author: tourist * created: 02.08.2018 18:01:48 **/ #include <bits/stdc++.h> using namespace std; const int md = (int) 1e9 + 7; class dsu { public: vector<int> p; int n; dsu(int _n) : n(_n) { p.resize(n); iota(p.begin(), p.end(), 0); } inline 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 main() { ios::sync_with_stdio(false); cin.tie(0); const int MAX = 1000010; vector<vector<int>> divs(MAX); for (int i = 2; i < MAX; i++) { for (int j = i; j < MAX; j += i) { divs[j].push_back(i); } } int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<vector<int>> ids(MAX); for (int i = 0; i < n; i++) { int x; cin >> x; for (int j : divs[x]) { ids[j].push_back(i); } } dsu d(n); for (int i = 2; i < MAX; i++) { if (divs[i].size() == 1) { for (int j = 1; j < (int) ids[i].size(); j++) { d.unite(ids[i][0], ids[i][j]); } } } int cnt = 0; for (int i = 0; i < n; i++) { cnt += (d.get(i) == i); } int ans = 1; for (int i = 0; i < cnt; i++) { ans = (ans + ans) % md; } ans = (ans + md - 2) % md; cout << ans << '\n'; } return 0; }