#include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); vector<string> split(const string &); const int N=1e6+69; int sito[N],rep[N],roz[N]; int re(int v) { if(v!=rep[v]) rep[v]=re(rep[v]); return rep[v]; } void uni(int a,int b) { a=re(a); b=re(b); if(a==b) return; rep[a]=b; roz[b]+=roz[a]; } int solve(vector<int> a) { sort(a.begin(),a.end()); for(int i=0;i<=1e6+9;i++) sito[i]=0; for(int i=2;i<=1e3+2;i++) { if(sito[i]) continue; for(int j=i*i;j<=1e6+3;j+=i) { sito[j]=i; } } for(int i=1;i<=1e6+3;i++) rep[i]=i, roz[i]=0; for(int i=1;i<=1e6+3;i++) if(sito[i]==0) sito[i]=i; while(!a.empty()) { int zm=a.back(); roz[re(zm)]++; while(zm!=1) { uni(a.back(),sito[zm]); zm/=sito[zm]; } a.pop_back(); } vector <int> wyn; for(int i=2;i<=1e6+1;i++) { if(roz[re(i)]) wyn.push_back(re(i)); } for(int i=0;i<roz[1];i++) { wyn.push_back(1e7+i); } sort(wyn.begin(),wyn.end()); wyn.resize(distance(wyn.begin(),unique(wyn.begin(),wyn.end()))); long long wynik=1, mod=1e9+7; for(int i=0;i<wyn.size();i++) { wynik*=2; wynik%=mod; } wynik-=2; if(wynik<0) wynik+=mod; return wynik; } int main() { ofstream fout(getenv("OUTPUT_PATH")); string t_temp; getline(cin, t_temp); int t = stoi(ltrim(rtrim(t_temp))); for (int t_itr = 0; t_itr < t; t_itr++) { string a_count_temp; getline(cin, a_count_temp); int a_count = stoi(ltrim(rtrim(a_count_temp))); string a_temp_temp; getline(cin, a_temp_temp); vector<string> a_temp = split(rtrim(a_temp_temp)); vector<int> a(a_count); for (int i = 0; i < a_count; i++) { int a_item = stoi(a_temp[i]); a[i] = a_item; } int result = solve(a); fout << result << "\n"; } fout.close(); return 0; } string ltrim(const string &str) { string s(str); s.erase( s.begin(), find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace))) ); return s; } string rtrim(const string &str) { string s(str); s.erase( find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), s.end() ); return s; } vector<string> split(const string &str) { vector<string> tokens; string::size_type start = 0; string::size_type end = 0; while ((end = str.find(" ", start)) != string::npos) { tokens.push_back(str.substr(start, end - start)); start = end + 1; } tokens.push_back(str.substr(start)); return tokens; }