#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 5;
const int logn = 20;
long long p[maxn];
inline bool cmp(const int &i, const int &j) { return p[i] < p[j]; }
int MOD;
class Matrix {
 public:
  int w, h;
  int dat[3][3];
  Matrix(int w_ = 0, int h_ = 0) : w(w_), h(h_) {
    memset(dat, 0, sizeof(dat));
    return;
  }
  inline int *operator[](const int &x) { return dat[x]; }
  inline Matrix operator*(const Matrix &oth) const {
    Matrix R(w, oth.h);
    for (int i = (0); i < (w); ++i)
      for (int j = (0); j < (oth.h); ++j)
        for (int k = (0); k < (h); ++k)
          (R[i][j] += 1ll * dat[i][k] * oth.dat[k][j] % MOD) %= MOD;
    return R;
  }
  inline Matrix &operator*=(const Matrix &oth) {
    return (*this = (*this) * oth);
  }
  inline void print() {
    printf("w = %d h = %d\n", w, h);
    for (int i = (0); i < (w); ++i) {
      printf("	");
      for (int j = (0); j < (h); ++j) printf("%d ", dat[i][j]);
      puts("");
    }
    return;
  }
} F[maxn], G[maxn], S[maxn][logn];
long long k;
int n, m;
int v[maxn], s[maxn], ord[maxn];
inline Matrix I(int w, int h) {
  Matrix R(w, h);
  for (int i = (0); i < (w); ++i) R[i][i] = 1;
  return R;
}
inline Matrix init(int s1, int s2) {
  Matrix R(2, 2);
  R[0][0] = s1, R[1][0] = s2;
  R[0][1] = 1;
  return R;
}
inline Matrix qpow(Matrix A, long long y) {
  Matrix R = I(A.w, A.h);
  for (; y; y >>= 1) {
    if (y & 1) R *= A;
    A *= A;
  }
  return R;
}
inline Matrix solve(long long l, long long r) {
  if (l > r) return I(2, 2);
  Matrix L = I(2, 2), M = I(2, 2), R = I(2, 2);
  if (l / n == r / n) {
    l %= n, r %= n;
    for (int k = logn - 1; k >= 0; --k)
      if (l + (1 << k) - 1 <= r) {
        M *= S[l][k];
        l += (1 << k);
      }
    return M;
  }
  if (l % n) {
    L = G[l % n];
    ((l += n - 1) /= n) *= n;
  }
  if (r % n != n - 1) {
    R = F[r % n];
    (r /= n) *= n;
    --r;
  }
  if (l <= r) {
    long long block = (r - l + 1) / n;
    M = qpow(F[n - 1], block);
  }
  Matrix P = L * M * R;
  return P;
}
map<long long, int> mp;
inline int calc(long long pos) {
  if (mp.find(pos) == mp.end()) return s[pos % n];
  return mp[pos];
}
int main() {
  scanf("%lld%d", &k, &MOD);
  if (k == 0) {
    puts("0");
    return 0;
  }
  if (k == 1) {
    printf("%d\n", 1 % MOD);
    return 0;
  }
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", s + i), s[i] %= MOD;
  scanf("%d", &m);
  for (int i = (0); i < (m); ++i)
    scanf("%lld%d", p + i, v + i), v[i] %= MOD, ord[i] = i, mp[p[i]] = v[i];
  sort(ord, ord + m, cmp);
  for (int i = (0); i < (n); ++i) S[i][0] = init(s[i], s[(i - 1 + n) % n]);
  for (int i = (0); i < (n); ++i) F[i] = (i ? F[i - 1] * S[i][0] : S[i][0]);
  for (int i = n - 1; i >= 0; --i)
    G[i] = (i != n - 1 ? S[i][0] * G[i + 1] : S[i][0]);
  for (int j = (1); j < (logn); ++j)
    for (int i = (0); i < (n); ++i)
      if (i + (1 << j - 1) < n)
        S[i][j] = S[i][j - 1] * S[i + (1 << j - 1)][j - 1];
  long long x = 1;
  Matrix A = I(2, 2);
  for (int it = (0); it < (m); ++it) {
    int i = ord[it];
    if (p[i] >= k) continue;
    A *= solve(x, p[i] - 1);
    Matrix B = init(calc(p[i]), calc(p[i] - 1));
    A *= B;
    if (p[i] + 1 < k && p[ord[it + 1]] != p[i] + 1) {
      B = init(calc(p[i] + 1), calc(p[i]));
      A *= B;
    }
    x = p[i] + 2;
  }
  A *= solve(x, k - 1);
  Matrix F0(1, 2);
  F0[0][0] = 1, F0[1][0] = 0;
  Matrix F = F0 * A;
  printf("%d\n", F[0][0]);
  return 0;
}
