void gauss(double A[][maxn]) { int i, r; for (i = 0; i < n; i++) { // swap r = i; for (int j = i+1; j < n; j++) { if (fabs(A[j][i]) > fabs(A[r][i])) r = j; } if (r != i) for (int j = 0; j <= n; j++) swap(A[r][j], A[i][j]);
// eliminate for (int j = n; j >= i; j--) { for (int k = i+1; k < n; k++) A[k][j] -= A[k][i] / A[i][i] * A[i][j]; }
// Jordan solution for (int i = n-1; i >= 0; i--) { for (int j = i+1; j < n; j--) A[i][n] -= A[i][j] * A[j][n]; A[i][n] /= A[i][i]; } } }
for (int i = 0; i < _n; i++) { for (int j = 0; j < _m; j++) for (int k = 0; k < (int)A[0].size(); k++) res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % mod; }
return res; }
Matrix matrix_pow(const Matrix &A, int exp) { int sz = A.size(); Matrix I(sz, vector<ll>(sz, 0)); for (int i = 0; i < sz; i++) I[i][i] = 1;
Matrix res = I, B = A; while (exp) { if (exp & 1) res = matrix_mul(res, B); B = matrix_mul(B, B); exp >>= 1; } return res; }
int main() { freopen("input.txt", "r", stdin); while (scanf("%d%d%d", &d, &n, &mod) == 3 && d) { // init // get data Matrix A(d, vector<ll>(d, 0)); Matrix F(d, vector<ll>(1, 0));
for (int i = 0; i < d; i++) { int x; scanf("%d", &x); A[0][i] = x; } for (int i = 1; i < d; i++) A[i][i-1] = 1; for (int i = d-1; i >= 0; i--) scanf("%d", &F[i][0]);
// data for (int i = 0; i < n; i++) scanf("%lld", &V[i]); for (int i = 0; i < n; i++) A[i][i] = 1; for (int i = 0; i < n; i++) { for (int j = 1; j <= d; j++) A[i][(i+j+n)%n] = A[i][(i-j+n)%n] = 1; }
typedef vector<vector<double> > Matrix; const int maxn = 100 + 10; const double eps = 1e-8; int n, deg[maxn], Inf[maxn]; vector<int> pre[maxn]; Matrix A;
void build() { for (int i = 0; i < n; i++) { A[i][i] = 1; for (auto u : pre[i]) A[i][u] -= 1.0 / deg[u]; if (i == 0) A[i][n] = 1; } }
void gauss_jordan() { int i, r; for (i = 0; i < n; i++) { r = i; for (int j = i+1; j < n; j++) { if (fabs(A[j][i]) > fabs(A[r][i])) r = j; } if (fabs(A[r][i]) < eps) continue; if (r != i) for (int j = 0; j <= n; j++) swap(A[r][j], A[i][j]);
// elimination for (int k = 0; k < n; k++) if (k != i) { for (int j = n; j >= i; j--) A[k][j] -= A[k][i] / A[i][i] * A[i][j]; } } }
void solve() { memset(Inf, 0, sizeof Inf); for (int i = n-1; i >= 0; i--) { if (fabs(A[i][i]) < eps && fabs(A[i][n]) > eps) Inf[i] = 1; for (int j = i+1; j < n; j++) if (fabs(A[i][j]) > eps && Inf[j] == 1) Inf[i] = 1; }
int q, u; scanf("%d", &q); while (q--) { scanf("%d", &u); u--; double res = 0; if (Inf[u]) printf("infinity\n"); else { res = fabs(A[u][u]) < eps ? 0.0 : A[u][n] / A[u][u]; printf("%.3lf\n", res); } } }
void init() { memset(deg, 0, sizeof deg); for (int i = 0; i < maxn; i++) pre[i].clear(); A = Matrix(n, vector<double>(n+1, 0)); }
int main() { freopen("input.txt", "r", stdin); int cas = 0; while (scanf("%d", &n) == 1 && n) { // init printf("Case #%d:\n", ++cas); init();
// get data int a, b; while (scanf("%d%d", &a, &b) == 2 && a) { // a->b a--, b--; deg[a]++, pre[b].push_back(a); } // get matrix build();
const int maxn = 500 + 10; typedef vector<vector<int> > Matrix; int tot = 0, n; Matrix A;
vector<int> primes;
void get_primes(int m) { primes.clear();
bool st[maxn]; memset(st, 0, sizeof st);
for (int i = 2; i <= m; i++) { if (st[i]) continue; primes.push_back(i); for (int j = i; j <= m; j += i) st[j] = 1; } }
int gauss_jordan(Matrix &A, int m, int n) { // m * n int i = 0, j = 0; for (; i < m && j <= n; j++) { // find r, A(r, j) != 0 int r = i; for (int k = i; k < m; k++) if (A[k][j]) { r = k; break; } if (A[r][j] == 0) continue; if (r != i) for (int k = 0; k <= n; k++) swap(A[r][k], A[i][k]);
// elimination for (int u = i+1; u < m; u++) if (A[u][j]) { for (int k = i; k <= n; k++) A[u][k] ^= A[i][k]; } i++; } return i; }
void init() { tot = 0; A = Matrix(maxn, vector<int>(maxn, 0)); }
int main() { freopen("input.txt", "r", stdin); int cas; cin >> cas; get_primes(500);
while (cas--) { init(); scanf("%d", &n); for (int i = 0; i < n; i++) { ll x; scanf("%lld", &x);
for (int j = 0; j < primes.size(); j++) { while (x % primes[j] == 0) { x /= primes[j], A[j][i] ^= 1; tot = max(tot, j); } } }
int r = gauss_jordan(A, tot+1, n); ll res = (1ll << (n-r)) - 1; printf("%lld\n", res); } }