import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.ArrayList;
class array_partition 
{
    static class Scanner
    {
        BufferedReader br;
        StringTokenizer tk=new StringTokenizer("");
        public Scanner(InputStream is) 
        {
            br=new BufferedReader(new InputStreamReader(is));
        }
        public int nextInt() throws IOException
        {
            if(tk.hasMoreTokens())
                return Integer.parseInt(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextInt();
        }
        public long nextLong() throws IOException
        {
            if(tk.hasMoreTokens())
                return Long.parseLong(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextLong();
        }
        public String next() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return next();
        }
        public String nextLine() throws IOException
        {
            tk=new StringTokenizer("");
            return br.readLine();
        }
        public double nextDouble() throws IOException
        {
            if(tk.hasMoreTokens())
                return Double.parseDouble(tk.nextToken());
            tk=new StringTokenizer(br.readLine());
            return nextDouble();
        }
        public char nextChar() throws IOException
        {
            if(tk.hasMoreTokens())
                return (tk.nextToken().charAt(0));
            tk=new StringTokenizer(br.readLine());
            return nextChar();
        }
        public int[] nextIntArray(int n) throws IOException
        {
            int a[]=new int[n];
            for(int i=0;i<n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArray(int n) throws IOException
        {
            long a[]=new long[n];
            for(int i=0;i<n;i++)
                a[i]=nextLong();
            return a;
        }
        public int[] nextIntArrayOneBased(int n) throws IOException
        {
            int a[]=new int[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextInt();
            return a;
        }
        public long[] nextLongArrayOneBased(int n) throws IOException
        {
            long a[]=new long[n+1];
            for(int i=1;i<=n;i++)
                a[i]=nextLong();
            return a;
        }
    
    
    }
    static class DSU
    {
        int n,p[],r[];
        DSU(int d)
        {
            n=d+50;
            p=new int[n];
            r=new int[n];
            for(int i=0;i<n;i++)
                p[i]=i;
        }
        int find(int x)
        {
            return p[x]==x?x:(p[x]=find(p[x]));
        }
        void union(int a,int b)
        {
            a=find(a);
            b=find(b);
            if(a==b)
                return;
            if(r[a]<r[b])
            {
                a^=b;b^=a;a^=b;
            }
            p[b]=a;
            if(r[a]==r[b])
                r[a]++;
        }
    }
    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int p[]=new int[1000001];
        for(int i=2;i<=1000000;i++)
            if(p[i]==0)
                for(int j=i;j<=1000000;j+=i)
                    if(p[j]==0)
                        p[j]=i;
        int t=in.nextInt();
        while(t--!=0)
        {
            int v=0;
            int n=in.nextInt();
            int cnt[]=new int[1000001];
            DSU d=new DSU(1000000);
            for(int i=0;i<n;i++)
            {
                int a=in.nextInt();
                if(a==1)
                    v++;
                else
                {
                    ArrayList<Integer> pr=new ArrayList<>();
                    while(a>1)
                    {
                        int e=p[a];
                        cnt[e]++;
                        pr.add(e);
                        while(a%e==0)
                            a/=e;
                    }
                    for(int j=1;j<pr.size();j++)
                        d.union(pr.get(0),pr.get(j));
                }
            }
            for(int i=2;i<=1000000;i++)
            {
                if(cnt[i]==0)
                    continue;
                if(d.find(i)==i)
                    v++;
            }
            long ans=1;
            long mod=1000000007;
            for(int i=0;i<v;i++)
                ans=(2*ans)%mod;
            ans-=2;
            if(ans<0)
                ans+=mod;
            out.println(ans);
            
        }
        
        out.close();
    }

}