#include <bits/stdc++.h> using namespace std; const int MOD = (int) 1e9 + 7; const int MAXN = (int) 1e5; const int MAXV = (int) 1e6; int arr[MAXN + 1], p2[MAXN + 1], last[MAXV + 1]; int low[MAXV + 1]; inline void prec() { int i, j; for(i = 2; i <= MAXV; i++) { if(low[i] == 0) { for(j = i; j <= MAXV; j += i) { low[j] = i; } } } } int sef[MAXN + 1]; int myfind(int x) { if(sef[x] == 0) return x; return sef[x] = myfind(sef[x]); } inline void myunion(int x, int y) { x = myfind(x), y = myfind(y); if(x != y) { sef[x] = y; } } int main() { int t, i, n, x; prec(); p2[0] = 1; for(i = 1; i <= MAXN; i++) { p2[i] = (p2[i - 1] * 2) % MOD; } cin >> t; while(t > 0) { t--; memset(last, 0, sizeof(last)); memset(sef, 0, sizeof(sef)); cin >> n; for(i = 1; i <= n; i++) { cin >> x; while(x > 1) { int cur = low[x]; if(last[low[x]] > 0) { myunion(last[low[x]], i); } last[low[x]] = i; while(low[x] == cur) { x /= cur; } } } memset(last, 0, sizeof(last)); int ans = 0; for(i = 1; i <= n; i++) { if(last[myfind(i)] == 0) ans++; last[myfind(i)] = 1; } cout << (p2[ans] - 2 + MOD) % MOD << "\n"; } return 0; }