#include <bits/stdc++.h>
using namespace std;
const int MK = 100;
const long long MOD = 998244353;
struct matrix {
  long long val[MK][MK];
  void clear() { memset(val, 0, sizeof(val)); }
  void m1() {
    clear();
    for (int i = 0; i < MK; ++i) {
      val[i][i] = 1;
    }
  }
  matrix(){};
};
matrix cross(const matrix &a, const matrix &b, long long MOD) {
  matrix res;
  res.clear();
  for (int i = 0; i < MK; ++i) {
    for (int j = 0; j < MK; ++j) {
      for (int k = 0; k < MK; ++k) {
        res.val[i][j] += a.val[i][k] * b.val[k][j];
        res.val[i][j] %= MOD;
      }
    }
  }
  return res;
}
matrix bipow(matrix a, long long pow, long long MOD) {
  if (pow == 1) return a;
  matrix res;
  res.m1();
  if (pow == 0) return res;
  while (pow) {
    if (pow & 1) res = cross(res, a, MOD);
    a = cross(a, a, MOD);
    pow >>= 1;
  }
  return res;
}
long long binup(long long a, long long pow, long long MOD) {
  if (pow == 0) return 1;
  if (pow & 1) return a * binup(a, pow - 1, MOD) % MOD;
  long long b = binup(a, pow / 2, MOD);
  return b * b % MOD;
}
long long powmod(long long a, long long b, long long m) {
  if (b == 1) return a;
  long long res = 1;
  while (b > 0)
    if (b & 1) {
      res = (res * a) % m;
      --b;
    } else {
      a = (a * a) % m;
      b >>= 1;
    }
  return res % m;
}
long long solve(long long a, long long b, long long m) {
  long long n = (long long)sqrt(m + .0) + 1;
  map<long long, long long> vals;
  for (long long i = n; i >= 1; --i) vals[powmod(a, i * n, m)] = i;
  for (long long i = 0; i <= n; ++i) {
    long long cur = (powmod(a, i, m) * b) % m;
    if (vals.count(cur)) {
      long long ans = vals[cur] * n - i;
      if (ans < m) return ans;
    }
  }
  return -1;
}
long long b[1000];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    cin >> b[i];
  }
  long long n, m;
  cin >> n >> m;
  matrix start;
  start.clear();
  for (int i = 0; i < k - 1; ++i) {
    start.val[0][i] = 0;
  }
  start.val[0][k - 1] = 1;
  matrix nxt;
  nxt.clear();
  for (int i = 0; i < k - 1; ++i) {
    nxt.val[i][i + 1] = 1;
  }
  for (int i = 0; i < k; ++i) {
    nxt.val[k - 1][i] = b[k - i - 1];
  }
  nxt = bipow(nxt, n - k, MOD - 1);
  start = cross(start, nxt, MOD - 1);
  long long pow = start.val[0][k - 1];
  long long g = 3;
  long long second = solve(binup(g, pow, MOD), m, MOD);
  if (second == -1) {
    cout << second;
  } else {
    cout << binup(g, second, MOD);
  }
}
