#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof (a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 100005;
const int MAX = 1000005;
const ll MOD = (ll)1e+9 + 7;

int n;
int dat[N];
ll pw2[N];
bool isPrime[MAX];
vll primeList;
int par[N];
int cnt;
int last[MAX];

int findSet(int x) {
    return par[x] == x ? x : par[x] = findSet(par[x]);
}

void uni(int a, int b) {
    int x = findSet(a), y = findSet(b);
    if (x == y) return;
    par[y] = x;
    --cnt;
}

void sieve() {
    reset(isPrime, true);
    for (ll i = 2; i < MAX; ++i) {
        if (isPrime[i]) {
            for (ll j = i * i; j < MAX; j += i) {
                isPrime[j] = 0;
            }
            primeList.push_back(i);
        }
    }
}

void read() {
    scanf("%d", &n);
    cnt = n;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &dat[i]);
        par[i] = i;
    }
}

void process(int where) {
    int x = dat[where];
    int idx = 0;
    while (primeList[idx] * primeList[idx] <= x) {
        if (x % primeList[idx] == 0) {
            if (last[primeList[idx]] != -1) {
                uni(last[primeList[idx]], where);
            }
            last[primeList[idx]] = where;
            while (x % primeList[idx] == 0) {
                x /= primeList[idx];
            }
        }
        ++idx;
    }

    if (x != 1) {
        if (last[x] != -1) {
            uni(last[x], where);
        }
        last[x] = where;
    }
}

void solve() {
    reset(last, -1);
    for (int i = 1; i <= n; ++i) {
        process(i);
    }
    ll ans = pw2[cnt] - 2;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    printf("%lld\n", ans);
}

int main() {
    int tc; scanf("%d", &tc);
    pw2[0] = 1;
    for (int i = 1; i < N; ++i) {
        pw2[i] = 1ll * 2 * pw2[i-1];
        pw2[i] %= MOD;
    }
    sieve();
    while (tc--) {
        read();
        solve();
    }
    return 0;
}