#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
int mod, s[N], n;
struct Matrix {
  int a[2][2];
  Matrix() { memset(a, 0, sizeof(a)); }
  inline Matrix operator*(const Matrix &b) {
    Matrix res;
    for (int i = 0; i <= 1; i++)
      for (int k = 0; k <= 1; k++)
        for (int j = 0; j <= 1; j++)
          res.a[i][j] = (res.a[i][j] + (long long)a[i][k] * b.a[k][j]) % mod;
    return res;
  }
  inline void print() {
    puts("----------------------------------------+");
    for (int i = 0; i <= 1; i++, puts(""))
      for (int j = 0; j <= 1; j++) printf("%d ", a[i][j]);
    puts("----------------------------------------+");
  }
} pre[17][N], E;
inline void Build() {
  E.a[0][0] = E.a[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    Matrix base;
    base.a[0][1] = 1, base.a[0][0] = s[i % n], base.a[1][0] = s[i - 1];
    pre[0][i] = base;
  }
  for (int i = 1; i <= 16; i++)
    for (int j = 1; j + (1 << i) - 1 <= n; j++)
      pre[i][j] = pre[i - 1][j] * pre[i - 1][j + (1 << i - 1)];
}
inline Matrix get(int l, int r) {
  Matrix res = E;
  for (int i = 16; i >= 0; i--)
    if (l + (1 << i) - 1 <= r) res = res * pre[i][l], l += (1 << i);
  return res;
}
inline Matrix Pow(Matrix x, long long y) {
  Matrix res = E;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) res = res * x;
  return res;
}
inline Matrix Just_DOIT(long long l, long long r) {
  if (l > r) return E;
  if (r - l + 1 <= n) {
    l = (l - 1) % n + 1, r = (r - 1) % n + 1;
    if (l <= r) return get(l, r);
    return get(l, n) * get(1, r);
  }
  long long l1 = (l + n - 1) / n * n + 1;
  long long r1 = r / n * n;
  return get(n - (l1 - l) + 1, n) * Pow(get(1, n), (r1 - l1 + 1) / n) *
         get(1, r - r1);
}
long long pos[N];
int v[N], id[N];
struct update {
  long long pos;
  Matrix t;
} q[N * 2];
int main() {
  long long k;
  scanf("%lld%d%d", &k, &mod, &n);
  if (k == 0) return puts("0"), 0;
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  Build();
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%lld%d", &pos[i], &v[i]), id[i] = i;
  sort(id + 1, id + m + 1, [](int a, int b) { return pos[a] < pos[b]; });
  int all = 0;
  for (int i = 1; i <= m; i++) {
    int at = id[i];
    if (pos[id[i - 1]] + 1 != pos[at]) {
      int a = v[at], b = s[(pos[at] - 1 + n) % n];
      Matrix base;
      base.a[0][0] = a, base.a[1][0] = b, base.a[0][1] = 1;
      q[++all] = (update){pos[at], base};
    }
    int b = v[at],
        a = pos[id[i + 1]] == pos[at] + 1 ? v[id[i + 1]] : s[(pos[at] + 1) % n];
    Matrix base;
    base.a[0][0] = a, base.a[1][0] = b, base.a[0][1] = 1;
    q[++all] = (update){pos[at] + 1, base};
  }
  long long ls = 0;
  Matrix res = E;
  for (int i = 1; i <= all; i++) {
    if (q[i].pos >= k) break;
    res = res * Just_DOIT(ls + 1, q[i].pos - 1) * q[i].t;
    ls = q[i].pos;
  }
  res = res * Just_DOIT(ls + 1, k - 1);
  printf("%d\n", res.a[0][0]);
}
