#include <bits/stdc++.h>

using namespace std;

typedef unsigned int ui;
typedef unsigned long long ul;
typedef long long sl;

sl a[100000],
   h[100000];

sl root(sl x)
{
    while (h[x] != x) {
        sl t = x;
        x = h[x];
        h[t] = h[x];
    }

    return x;
}

void uni(sl x, sl y)
{
    sl rx = root(x),
       ry = root(y);

    if (rx != ry)
        h[ry] = rx;
}

map<sl, vector<sl>> m;

sl gcd(sl x, sl y)
{
    if (x == 0)
        return y;

    return gcd(y % x, x);
}

sl p[1000001],
   np;

void er()
{
    for (sl i = 2; i <= 1000000; ++i) {
        if (p[i] == 0) {
            for (sl j = i * i; j <= 1000000; j += i)
                p[j] = 1;
        }
    }

    for (sl i = 2; i <= 1000000; ++i)
        if (!p[i])
            p[np++] = i;
}

void getm(sl x)
{
    sl ax = a[x];
    for (int i = 0; p[i] * p[i] <= ax; ++i) {
        if (ax % p[i] == 0) {
            m[p[i]].push_back(x);
            while (ax % p[i] == 0)
                ax /= p[i];
        }
    }
    if (ax > 1)
        m[ax].push_back(x);
}

sl mod = 1000000007;
sl pw(sl x, sl cp)
{
    if (cp == 0)
        return 1;
    if (cp == 1)
        return x;

    sl r = pw(x, cp / 2);
    r = (r * r) % mod;
    if (cp & 1)
        r = (r * x) % mod;
    return r;
}

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);

    er();

    int t;
    cin >> t;

    for (; t; --t) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            getm(i);
            h[i] = i;
        }

        for (auto& cp : m) {

            sl z = cp.second.size(),
               zx = cp.second[0];
            for (sl i = 1; i < z; ++i)
                uni(cp.second[i], zx);
        }
        m.clear();

        set<sl> d;
        for (int i = 0; i < n; ++i)
            d.insert(root(h[i]));

        sl r = pw(2, d.size());
        cout << (r + mod - 2) % mod << '\n';
    }

    return 0;
}