#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  write(a);
  puts("");
}
const long long N = 50005, size = 2;
struct matrix {
  long long a[2][2];
} tree[N << 2], ans;
long long n, k, s[N], mod, m;
matrix operator*(matrix x, matrix y) {
  matrix tmp;
  for (long long i = 0; i < size; i++)
    for (long long j = 0; j < size; j++) {
      tmp.a[i][j] = 0;
      for (long long k = 0; k < size; k++) {
        tmp.a[i][j] = (tmp.a[i][j] + (long long)x.a[i][k] * y.a[k][j]) % mod;
      }
    }
  return tmp;
}
inline matrix mm(long long a, long long b) {
  matrix tmp;
  tmp.a[1][0] = 1;
  tmp.a[1][1] = b;
  tmp.a[0][1] = a;
  tmp.a[0][0] = 0;
  return tmp;
}
void build(long long l, long long r, long long nod) {
  if (l == r) {
    tree[nod] = mm(s[(l + n - 2) % n], s[(l + n - 1) % n]);
    return;
  }
  long long mid = (l + r) >> 1;
  build(l, mid, nod << 1);
  build(mid + 1, r, nod << 1 | 1);
  tree[nod] = tree[nod << 1] * tree[nod << 1 | 1];
}
matrix ask(long long l, long long r, long long i, long long j, long long nod) {
  if (l == i && r == j) return tree[nod];
  long long mid = (l + r) >> 1;
  if (j <= mid)
    return ask(l, mid, i, j, nod << 1);
  else if (i > mid)
    return ask(mid + 1, r, i, j, nod << 1 | 1);
  else
    return ask(l, mid, i, mid, nod << 1) *
           ask(mid + 1, r, mid + 1, j, nod << 1 | 1);
}
map<long long, long long> M;
matrix ksm(matrix ans, matrix a, long long k) {
  for (; k; k >>= 1) {
    if (k & 1) ans = ans * a;
    a = a * a;
  }
  return ans;
}
signed main() {
  k = read();
  mod = read();
  if (k == 0) {
    puts("0");
    return 0;
  }
  n = read();
  for (long long i = 0; i < n; i++) s[i] = read();
  m = read();
  for (long long i = 1; i <= m; i++) {
    long long pos = read();
    M[pos] = read();
  }
  if (!M.count(k)) M[k] = s[k % n];
  build(0, n - 1, 1);
  ans.a[0][0] = 0;
  ans.a[0][1] = 1;
  long long dq = 1;
  while (dq < k) {
    if (M.count(dq - 1) || M.count(dq)) {
      ans = ans * mm(M.count(dq - 1) ? M[dq - 1] : s[(dq + n - 1) % n],
                     M.count(dq) ? M[dq] : s[dq % n]);
      dq++;
    } else {
      long long t = M.lower_bound(dq)->first;
      dq++;
      if (t / n == dq / n) {
        ans = ans * ask(0, n - 1, dq % n, t % n, 1);
      } else {
        ans = ans * ask(0, n - 1, dq % n, n - 1, 1);
        ans = ksm(ans, tree[1], (t - dq / n * n - n) / n);
        ans = ans * ask(0, n - 1, 0, t % n, 1);
      }
      dq = t;
    }
  }
  cout << ans.a[0][1] % mod << endl;
}
