/*input
3
3
2 3 1
3
2 3 6
4
2 3 6 1
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct DSU
{
    vector<int>pa;
    DSU(int n = 1)
    {
        pa = vector<int>(n + 3, -1);
    }
    int root(int i)
    {
        if (pa[i] < 0)
            return i;
        return pa[i] = root(pa[i]);
    }
    int size(int i)
    {
        return -pa[root(i)];
    }
    int merge(int a, int b)
    {
        a = root(a);
        b = root(b);
        if (a == b)
            return a;
        if (pa[a] < pa[b])
            swap(a, b);
        pa[b] += pa[a];
        pa[a] = b;
        return b;
    }
};
const ll modulo = 1000000007;
vector<int> primes[1000001];
int main()
{
    for (int i = 2; i < 1000001; i++)
    {
        if (primes[i].empty())
        {
            for (int j = i; j < 1000001; j += i)
            {
                primes[j].push_back(i);
            }
        }
    }
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    int T;
    cin >> T;
    while (T--)
    {
        int N;
        cin >> N;
        int A[N + 1];
        for (int i = 1; i <= N; i++)
            cin >> A[i];
        DSU X(N + 2);
        map<int, int>B;
        for (int i = 1; i <= N; i++)
        {
            for (int c : primes[A[i]])
            {
                if (B.count(c))
                {
                    X.merge(i, B[c]);
                }
                B[c] = i;
            }
        }




        ll ans = 1;
        for (int i = 1; i <= N; i++)
        {
            if (X.root(i) == i)
            {
                ans *= 2;
                ans %= modulo;
            }
        }
        ans -= 2;
        ans += modulo;
        ans %= modulo;
        cout << ans << "\n";
    }

}