// In the name of God.
// You're anything and We're nothing.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 17, mod = 1e9 + 7;
struct Dsu{
    int par[maxn];
    vector<pair<int, int> > history;
    vector<int> records;
    Dsu(){  memset(par, -1, sizeof par);  }
    Dsu& operator = (const Dsu &od){
        history = od.history;
        records = od.records;
        memcpy(par, od.par, sizeof par);
        return *this;
    }
    void record(){  records.push_back(history.size());  }
    void undo(){
        assert(records.size());
        int when = records.back();  records.pop_back();
        while(history.size() > when){
            int u = history.back().first, sz = history.back().second, v = par[u];
            par[v] -= sz, par[u] = sz;
            history.pop_back();
        }
    }
    int root(int v){
        while(par[v] >= 0)  v = par[v];
        return v;
    }
    bool fri(int v, int u){
        return root(v) == root(u);
    }
    bool merge(int v, int u){
        v = root(v), u = root(u);
        if(v == u)  return 0;
        if(par[v] > par[u])  swap(v, u);
        history.push_back({u, par[u]});
        par[v] += par[u], par[u] = v;
        return 1;
    }
}  dsu;
int t, a[maxn];
vector<int> prs[maxn];
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    for(int i = 2; i < maxn; i++)
        if(prs[i].empty())
            for(int j = i; j < maxn; j += i)
                prs[j].push_back(i);
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        dsu = Dsu();
        for(int i = 0; i < n; i++){
            cin >> a[i];
            for(auto p : prs[ a[i] ])
                dsu.merge(p, a[i]);
        }
        int ans = 1;
        set<int> s;
        for(int i = 0; i < n; i++)
            if(a[i] == 1 || s.insert(dsu.root(a[i])).second)
                ans = ans * 2 % mod;
        ans -= 2;
        if(ans < 0)
            ans += mod;
        cout << ans << '\n';
    }
}