#include <bits/stdc++.h>

using namespace std;

const int N = 1000002;

int g[N];

int parent[N];
int size[N];

int get_parent(int v) {
    if (v == parent[v]) {
        return v;
    }
    return parent[v] = get_parent(parent[v]);
}

void union_sets(int a, int b) {
    a = get_parent(a);
    b = get_parent(b);
    if (a != b) {
        if (size[a] < size[b]) {
            swap(a, b);
        }
        parent[b] = a;
        size[a] += size[b];
    }
}

void init_dsu(int n) {
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        size[i] = 1;
    }
}

long long MOD = 1000000007;
long long binpow(long long a, long long x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 0) {
        long long t = binpow(a, x/2);
        return t * t % MOD;
    } else {
        return a * binpow(a, x-1) % MOD;
    }
}

void solve() {
    int n;
    cin >> n;
    init_dsu(n);
    memset(g, 255, sizeof(g));
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        for (int j = 2; j * j <= x; j++) {
            if (x % j == 0) {
                if (g[j] != -1) {
                    union_sets(g[j], i);
                }
                g[j] = i;
                while (x % j == 0) {
                    x /= j;
                }
            }
        }
        if (x > 1) {
            int j = x;
            if (g[j] != -1) {
                union_sets(g[j], i);
            }
            g[j] = i;
        }
    }
    set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(get_parent(i));
    }
    cout << (binpow(2, s.size()) - 2 + MOD) % MOD << endl;
}

int main() {
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        solve();
    }
    return 0;
}