#include <bits/stdc++.h>
using namespace std;
namespace io {
const int bufsz = 1 << 24, pufsz = 1 << 8;
static char buf[bufsz], puf[pufsz], *p1, *p2, *pp = puf;
struct flusher {
  ~flusher() { (fwrite(puf, 1, pp - puf, stdout), pp = puf); }
} flusher;
template <class type>
void inline read(type &a) {
  char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufsz, stdin), p1 == p2)
           ? EOF
           : *p1++);
  for (; !(c >= '0' && c <= '9');
       c = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, bufsz, stdin), p1 == p2)
                ? EOF
                : *p1++))
    ;
  for (a = 0; (c >= '0' && c <= '9'); a *= 10, a += c & 15,
      c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufsz, stdin), p1 == p2)
               ? EOF
               : *p1++))
    ;
}
template <class type>
void inline write(type a, char c = '\n') {
  static int d[20];
  int s = d[0] = 0;
  for (; a; d[s++] = a % 10, a /= 10)
    ;
  for (s || (s = 1); s;
       (*pp++ = d[--s] + 48,
       pp - puf == pufsz && (fwrite(puf, 1, pp - puf, stdout), pp = puf)))
    ;
  (*pp++ = c,
   pp - puf == pufsz && (fwrite(puf, 1, pp - puf, stdout), pp = puf));
}
}  // namespace io
using namespace io;
const int nsz = 5e4, bsz = 15, b2sz = bsz << 1, Bsz = 1 << bsz, Bfull = Bsz - 1;
int n, m, mod, ans, a[nsz + 5], id[nsz + 5], w[nsz + 5];
long long k, t[nsz + 5];
struct matrix {
  long long OO, OI, IO, II;
  matrix() {}
  matrix(long long w) : OO(w), OI(0), IO(0), II(w) {}
  matrix(long long OO, long long OI, long long IO, long long II)
      : OO(OO), OI(OI), IO(IO), II(II) {}
  inline matrix &operator*=(const matrix &b) {
    const long long _OO = OO, _IO = IO;
    OO = (_OO * b.OO + OI * b.IO) % mod;
    OI = (_OO * b.OI + OI * b.II) % mod;
    IO = (_IO * b.OO + II * b.IO) % mod;
    II = (_IO * b.OI + II * b.II) % mod;
    return *this;
  }
  friend inline matrix operator*(const matrix &a, const matrix &b) {
    return matrix(
        (a.OO * b.OO + a.OI * b.IO) % mod, (a.OO * b.OI + a.OI * b.II) % mod,
        (a.IO * b.OO + a.II * b.IO) % mod, (a.IO * b.OI + a.II * b.II) % mod);
  }
  friend inline ostream &operator<<(ostream &out, const matrix &a) {
    return out << "{" << a.OO << ',' << a.OI << "}\n{" << a.IO << ',' << a.II
               << "}";
  }
};
matrix I, A[nsz + 5], pre[nsz + 5], suf[nsz + 5];
matrix B0, B1, B2, pw0[Bsz + 5], pw1[Bsz + 5], pw2[Bsz + 5];
struct vec {
  long long O, I;
  vec() {}
  vec(long long O, long long I) : O(O), I(I) {}
  inline vec &operator*=(const matrix &b) {
    const long long _O = O;
    O = (_O * b.OO + I * b.IO) % mod;
    I = (_O * b.OI + I * b.II) % mod;
    return *this;
  }
};
struct segment_tree {
  int sz;
  matrix tr[4 * nsz + 5];
  void inline init(const int n, const matrix *a) {
    for (sz = 1; sz < n; sz <<= 1)
      ;
    for (int i = 0; i < n; ++i) tr[i + sz] = a[i];
    for (int i = sz - 1; i; --i) tr[i] = tr[i << 1] * tr[i << 1 | 1];
  }
  matrix inline qry(int l, int r) {
    matrix rl = I, rr = I;
    for (l += sz, r += sz + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) rl *= tr[l++];
      if (r & 1) rr = tr[--r] * rr;
    }
    return rl * rr;
  }
};
segment_tree tr;
matrix inline make(const long long w0, const long long w1) {
  return matrix(0, w0, 1, w1);
}
void inline pow(vec &a, const long long p) {
  a *= pw0[p & Bfull], a *= pw1[(p >> bsz) & Bfull],
      a *= pw2[(p >> b2sz) & Bfull];
}
void inline upd(vec &a, const long long w0, const long long w1) {
  const long long _I = a.I;
  a.I = (a.O * w0 + _I * w1) % mod, a.O = _I;
}
void inline qry(vec &a, long long l, long long r) {
  if (l > r) return;
  long long i = l / n, j = r / n;
  l -= i * n, r -= j * n;
  if (i == j)
    a *= tr.qry(l, r);
  else
    a *= suf[l], pow(a, j - i - 1), a *= pre[r];
}
bool inline by_time(const int i, const int j) { return t[i] < t[j]; }
template <class type>
void inline rearrange(const int n, type *a, const int *p) {
  static type b[nsz + 5];
  for (int i = 1; i <= n; ++i) b[i] = a[p[i]];
  memcpy(a + 1, b + 1, sizeof(type) * n);
}
void inline init() {
  I = matrix(1);
  for (int i = 0; i < n; ++i) A[i] = make(a[i], a[(i + 1) % n]);
  tr.init(n, A);
  pre[0] = A[0];
  for (int i = 0; i < n - 1; ++i) pre[i + 1] = pre[i] * A[i + 1];
  suf[n - 1] = A[n - 1];
  for (int i = n - 1; i >= 1; --i) suf[i - 1] = A[i - 1] * suf[i];
  pw0[0] = I, B0 = suf[0];
  for (int i = 1; i <= Bsz; ++i) pw0[i] = pw0[i - 1] * B0;
  pw1[0] = I, B1 = pw0[Bsz];
  for (int i = 1; i <= Bsz; ++i) pw1[i] = pw1[i - 1] * B1;
  pw2[0] = I, B2 = pw1[Bsz];
  for (int i = 1; i <= Bsz; ++i) pw2[i] = pw2[i - 1] * B2;
  for (int i = 1; i <= m; ++i) id[i] = i;
  sort(id + 1, id + m + 1, by_time);
  rearrange(m, t, id);
  rearrange(m, w, id);
}
void inline solve() {
  if (k < 2) return (void)(k % mod);
  k -= 2;
  vec v(0, 1);
  long long lst = 0;
  for (int i = 1; i <= m; ++i) {
    const long long cur = t[i];
    if (cur > k + 1) break;
    qry(v, lst, t[i] - 2), upd(v, a[(cur - 1 + n) % n], w[i]);
    for (; i + 1 <= m && t[i] + 1 == t[i + 1] && t[i] + 1 <= k;
         upd(v, w[i], w[i + 1]), ++i)
      ;
    if (t[i] <= k) upd(v, w[i], a[(t[i] + 1) % n]);
    lst = t[i] + 1;
  }
  qry(v, lst, k), ans = v.I;
}
int main() {
  read(k), read(mod), read(n);
  for (int i = 0; i < n; ++i) read(a[i]);
  read(m);
  for (int i = 1; i <= m; ++i) read(t[i]), read(w[i]);
  init();
  solve();
  write(ans);
}
