#define debug_iv_ac ios::sync_with_stdio(false);cin.tie(NULL);
#include <bits/stdc++.h>
 
#define pb push_back
#define  mp make_pair
#define pp pop_back
#define pf push_front
#define fi first
#define se second
#define MAXN 1000005
typedef long long ll;    
using namespace std;
#define pi pair<ll,ll>

ll mod = 1e9+7;

int spf[MAXN];
vector<int> v[MAXN];
int vis[MAXN];
int cnt = 0;
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
 
        // marking smallest prime factor for every
        // number to be itself.
        spf[i] = i;
 
    // separately marking spf for every even
    // number as 2
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;
 
    for (int i=3; i*i<MAXN; i++)
    {
        // checking if i is prime
        if (spf[i] == i)
        {
            // marking SPF for all numbers divisible by i
            for (int j=i*i; j<MAXN; j+=i)
 
                // marking spf[j] if it is not 
                // previously marked
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

void dfs(int r)
{
    //cout<<r<<" ";
    vis[r]++;
    for(auto it:v[r])
    {
        if(vis[it]) continue;
        dfs(it);
    }
}

ll power(ll x, ll y,ll p)
{
    ll res = 1;      // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;  
    }
    return res;
}

int main()
{
    sieve();
   int t;
   cin>>t;
   while(t--)
   {
       int n;
       cin>>n;
       for(int i=1;i<=MAXN;i++) v[i].clear(),vis[i] = -1;
       int c = 0;
       for(int i=1;i<=n;i++)
       {
           int x;
           cin>>x;
           if(x==1) vis[1] = 0,c++;
           set<int> s;
           while(x!=1)
           {
               int y = spf[x];
               s.insert(y);
               while(x%y==0) x/=y;
           }
           if(x>1)
           s.insert(x);
           for(auto it:s)
           {
               //cout<<it<<" ";
               vis[it] = 0;
               for(auto it1:s)
               {
                   if(it == it1) continue;
                   v[it].pb(it1);
                   v[it1].pb(it);
               }
           }
           //cout<<endl;
       }
       ll p = 0,cnt=0;
       for(int i=1;i<MAXN;i++)
       {
           if(vis[i] == 0)
           {
               dfs(i);
               p++;
               //cout<<endl;
           }
       }
       if(c>1)
       p+=c-1;
       //cout<<p<<endl;
        ll ans = 1ll;
       for(int i=1;i<=p;i++) ans = (ans*2ll)%mod;
       ans = (ans-2+mod)%mod;
       cout<<ans<<endl;
   }
   return 0;
}