#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  char ch;
  bool flag = false;
  while (!isdigit(ch = getchar())) flag |= ch == '-';
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  if (flag) x = -x;
}
inline long long input() {
  long long x;
  char ch;
  bool flag = false;
  while (!isdigit(ch = getchar())) flag |= ch == '-';
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return flag ? -x : x;
}
long long mod;
inline long long add(long long x, long long y) {
  x += y;
  return x >= mod ? x - mod : x;
}
inline void inc(long long &x, long long y) {
  x += y;
  x -= x >= mod ? mod : 0;
}
inline long long Power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod, y >>= 1;
  }
  return res;
}
template <class T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <class T>
void chkmin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
T gcd(T x, T y) {
  return !y ? x : gcd(x % y, y);
}
long long k;
long long n, m, tot, tota;
long long s[100005];
struct mdf {
  long long pos;
  long long x, y, z;
} p[100005];
inline bool operator<(const mdf &x, const mdf &y) { return x.pos < y.pos; }
struct Matrix {
  long long a[2][2];
  long long *operator[](const long long x) { return a[x]; }
  Matrix(long long x = 0, long long y = 0, long long z = 0) {
    a[0][0] = 0, a[1][0] = z, a[0][1] = x, a[1][1] = y;
  }
} e;
Matrix operator*(Matrix a, Matrix b) {
  Matrix res;
  res[0][0] = add((long long)a[0][0] * b[0][0] % mod,
                  (long long)a[0][1] * b[1][0] % mod);
  res[0][1] = add((long long)a[0][0] * b[0][1] % mod,
                  (long long)a[0][1] * b[1][1] % mod);
  res[1][0] = add((long long)a[1][0] * b[0][0] % mod,
                  (long long)a[1][1] * b[1][0] % mod);
  res[1][1] = add((long long)a[1][0] * b[0][1] % mod,
                  (long long)a[1][1] * b[1][1] % mod);
  return res;
}
Matrix operator^(Matrix a, long long y) {
  Matrix res = e, x = a;
  while (y) {
    if (y & 1) res = res * x;
    x = x * x, y >>= 1;
  }
  return res;
}
Matrix T[100005 << 2];
void build(long long rt, long long l, long long r) {
  if (l == r) return T[rt] = Matrix(s[l - 1], s[l % n], 1), void();
  build(rt << 1, l, ((l + r) >> 1)), build(rt << 1 | 1, ((l + r) >> 1) + 1, r);
  T[rt] = T[rt << 1] * T[rt << 1 | 1];
}
void Modify(long long rt, long long l, long long r, mdf &x) {
  if (l == r) return T[rt][x.x][x.y] = x.z, void();
  if ((x.pos - 1) % n + 1 <= ((l + r) >> 1))
    Modify(rt << 1, l, ((l + r) >> 1), x);
  else
    Modify(rt << 1 | 1, ((l + r) >> 1) + 1, r, x);
  T[rt] = T[rt << 1] * T[rt << 1 | 1];
}
void query(long long rt, long long l, long long r, long long L, long long R,
           Matrix &res) {
  if (L <= l && r <= R) return res = res * T[rt], void();
  if (L <= ((l + r) >> 1)) query(rt << 1, l, ((l + r) >> 1), L, R, res);
  if (R > ((l + r) >> 1)) query(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, res);
}
Matrix Query(long long x = 0) {
  if (!x) return T[1];
  Matrix res = e;
  query(1, 1, n, 1, x, res);
  return res;
}
long long Index(long long x) { return !x ? -1 : (x - 1) / n; }
signed main() {
  e[0][0] = e[1][1] = 1;
  read(k), --k, mod = input(), n = input();
  for (long long i = 0; i < n; ++i) s[i] = input();
  m = input();
  for (long long i = 1; i <= m; ++i) {
    long long a, b;
    read(a), read(b);
    if (a > k) continue;
    p[++tot] = (mdf){a, 1, 1, b};
    p[++tot] = (mdf){a + 1, 0, 1, b};
  }
  if (!~k || mod == 1) return puts("0"), 0;
  if (!k) return puts("1"), 0;
  sort(p + 1, p + tot + 1), tota = tot;
  for (long long i = 1; i <= tot; ++i)
    if (Index(p[i].pos) == Index(k)) {
      tota = i - 1;
      break;
    }
  Matrix ans(1), A;
  build(1, 1, n), A = Query();
  for (long long l = 1, r = 0; l <= tota; l = r + 1) {
    ans = ans * (A ^ (Index(p[l].pos) - Index(p[r].pos) - 1));
    r = l;
    while (r < tota && Index(p[r + 1].pos) == Index(p[l].pos)) ++r;
    for (long long i = l; i <= r; ++i)
      Modify(1, 1, n, p[i]), p[i].z = s[(p[i].pos + p[i].x - 1) % n];
    ans = ans * Query();
    for (long long i = l; i <= r; ++i) Modify(1, 1, n, p[i]);
  }
  ans = ans * (A ^ (Index(k) - Index(p[tota].pos) - 1));
  for (long long i = tota + 1; i <= tot; ++i) Modify(1, 1, n, p[i]);
  ans = ans * Query((k - 1) % n + 1);
  printf("%lld\n", ans[0][1] % mod);
  return 0;
}
