#include <bits/stdc++.h>
using namespace std;
struct node {
  long long mat[2][2];
} s[100005 << 2], e, tmp, ano, ee;
struct dif {
  long long pos;
  int v;
} a[100005];
int S[100005], p, n, m, i, j, now, nxt;
bool cmp(dif aa, dif bb) { return aa.pos < bb.pos; }
node mul(node aa, node bb) {
  struct node ret;
  int i, j, k;
  for (i = 0; i < 2; ++i)
    for (j = 0; j < 2; ++j)
      for (ret.mat[i][j] = k = 0; k < 2; ++k)
        (ret.mat[i][j] += aa.mat[i][k] * bb.mat[k][j]) %= p;
  return ret;
}
void build(int k, int l, int r) {
  if (l == r) {
    s[k].mat[0][0] = S[l];
    s[k].mat[1][0] = S[l - 1];
    s[k].mat[0][1] = 1;
  } else
    build((k << 1), l, (l + r >> 1)), build((k << 1 | 1), (l + r >> 1) + 1, r),
        s[k] = mul(s[(k << 1)], s[(k << 1 | 1)]);
}
node prod(int k, int l, int r, int x, int y) {
  if (x <= l && r <= y) return s[k];
  if (x > r || y < l) return e;
  return mul(prod((k << 1), l, (l + r >> 1), x, y),
             prod((k << 1 | 1), (l + r >> 1) + 1, r, x, y));
}
node ksm(node aa, long long mi) {
  struct node ret = e;
  for (; mi; mi >>= 1, aa = mul(aa, aa))
    if (mi & 1) ret = mul(ret, aa);
  return ret;
}
node cheng(long long l, long long r) {
  if (l > r) return e;
  long long l_ = (l - 1) / n, r_ = (r - 1) / n;
  l = l - l_ * n;
  r = r - r_ * n;
  if (l_ == r_) {
    return prod(1, 1, n, l, r);
  }
  if (r_ == l_ + 1) {
    return mul(prod(1, 1, n, l, n), prod(1, 1, n, 1, r));
  }
  return mul(mul(prod(1, 1, n, l, n), ksm(prod(1, 1, n, 1, n), r_ - l_ - 1)),
             prod(1, 1, n, 1, r));
}
long long F[2][2], k;
int main() {
  e.mat[0][0] = e.mat[1][1] = 1;
  cin >> k >> p >> n;
  for (i = 0; i < n; ++i) cin >> S[i];
  cin >> m;
  for (i = 1; i <= m; ++i) {
    cin >> a[i].pos >> a[i].v;
    if (a[i].pos >= k) --m, --i;
  }
  S[n] = S[0];
  if (k == 0) return cout << 0, 0;
  sort(a + 1, a + m + 1, cmp);
  build(1, 1, n);
  F[0][0] = 1;
  for (i = 1; i <= m; ++i) {
    ee.mat[0][0] = a[i].v;
    if (a[i - 1].pos == a[i].pos - 1) {
      ee.mat[1][0] = a[i - 1].v;
    } else
      ee.mat[1][0] = S[(a[i].pos - 1) % n];
    ee.mat[0][1] = 1;
    tmp = mul(cheng(a[i - 1].pos + 2 - (i == 1), a[i].pos - 1), ee);
    if (a[i + 1].pos != a[i].pos + 1 && a[i].pos + 1 != k) {
      ee.mat[0][0] = S[(a[i].pos + 1) % n];
      ee.mat[0][1] = 1;
      ee.mat[1][0] = a[i].v;
      tmp = mul(tmp, ee);
    }
    nxt = now ^ 1;
    F[nxt][0] = (F[now][0] * tmp.mat[0][0] + F[now][1] * tmp.mat[1][0]) % p;
    F[nxt][1] = (F[now][0] * tmp.mat[0][1] + F[now][1] * tmp.mat[1][1]) % p;
    now = nxt;
  }
  tmp = cheng(a[m].pos + 2 - (m == 0), k - 1);
  cout << (F[now][0] * tmp.mat[0][0] + F[now][1] * tmp.mat[1][0]) % p;
}
