#include <bits/stdc++.h> using namespace std; #define N 1000010 int a[N], p[N], flag[N], ID[N]; int father[N << 1], vis[N << 1]; const int mod = 1e9 + 7; int find(int x) { if (x == father[x]) return x; return father[x] = find(father[x]); } void merge(int x, int y) { x = find(x), y = find(y); if (x < y) father[y] = x; else father[x] = y; } int main() { for (int i = 2; i < N; ++i) { if (!flag[i]) { p[++p[0]] = i; for (int j = i; j < N; j += i) flag[j] = 1; } } int T, n, tot; cin >> T; while (T--) { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), father[i] = i; if (n == 1) {puts("0"); continue;} tot = n; for (int i = 1; i <= p[0]; ++i) father[++tot] = tot, ID[p[i]] = tot; for (int i = 1; i <= n; ++i) { int x = a[i]; for (int j = 1; p[j] * p[j] <= x; ++j) { if (x % p[j] == 0) merge(i, ID[p[j]]); while (x % p[j] == 0) x /= p[j]; } if (x != 1) merge(i, ID[x]); } int ans = 1; for (int i = 1; i <= n; ++i) { if (i == father[i]) ans = ans * 2 % mod; } ans -= 2; if (ans < 0) ans += mod; printf("%d\n", ans); } return 0; }