#include <bits/stdc++.h>
using std::sort;
const int N = 50005;
inline long long max(const long long a, const long long b) {
  return a > b ? a : b;
}
inline long long min(const long long a, const long long b) {
  return a < b ? a : b;
}
long long k;
int n, m, mod, cnt;
struct Query {
  int v, z;
  long long x;
  bool operator<(const Query& t) const { return x < t.x; }
} g[N << 1];
struct Matrix {
  int w[2][2];
  inline void set(const int x) {
    w[0][0] = w[1][1] = x;
    w[0][1] = w[1][0] = 0;
  }
} s[N], tem, res;
inline Matrix operator*(const Matrix& a, const Matrix& b) {
  static Matrix res;
  res.set(0);
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
        res.w[i][j] = (res.w[i][j] + (long long)a.w[i][k] * b.w[k][j]) % mod;
  return res;
}
inline Matrix power(const Matrix& _x, long long k) {
  static Matrix res, x;
  x = _x, res.set(1);
  while (k) {
    if (k & 1) res = res * x;
    x = x * x;
    k >>= 1;
  }
  return res;
}
struct SegmentTree {
  Matrix v[N << 2];
  inline void update(int x) { v[x] = v[x << 1] * v[x << 1 | 1]; }
  void build(int l = 0, int r = n - 1, int u = 1) {
    if (l == r)
      v[u] = s[r];
    else {
      int mid = l + r >> 1;
      build(l, mid, u << 1);
      build(mid + 1, r, u << 1 | 1);
      update(u);
    }
  }
  void change(int x, const Matrix& c, int l = 0, int r = n - 1, int u = 1) {
    if (l == r)
      v[u] = c;
    else {
      int mid = l + r >> 1;
      if (x <= mid)
        change(x, c, l, mid, u << 1);
      else
        change(x, c, mid + 1, r, u << 1 | 1);
      update(u);
    }
  }
  Matrix query(int ql = 0, int qr = n - 1, int l = 0, int r = n - 1,
               int u = 1) {
    if (l >= ql && r <= qr) return v[u];
    int mid = l + r >> 1;
    if (qr <= mid) return query(ql, qr, l, mid, u << 1);
    if (mid < ql) return query(ql, qr, mid + 1, r, u << 1 | 1);
    return query(ql, qr, l, mid, u << 1) *
           query(ql, qr, mid + 1, r, u << 1 | 1);
  }
} sgt;
void prework() {
  scanf("%lld%d%d", &k, &mod, &n);
  int v;
  long long x;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &v), v %= mod;
    s[i].w[0][1] = s[(i + n - 1) % n].w[1][1] = v;
    s[i].w[1][0] = 1;
  }
  scanf("%d", &m);
  g[cnt++].x = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%lld%d", &x, &v);
    if (x < k) g[cnt++] = {v, 0, x};
    if (x <= k) g[cnt++] = {v, 1, x - 1};
  }
  sort(g + 1, g + cnt), sgt.build();
}
int main() {
  prework();
  if (!k) return puts("0"), 0;
  --k, res.w[0][1] = 1;
  for (int i = 1, j; i < cnt;) {
    long long t = g[i].x / n - g[i - 1].x / n - (i > 1);
    res = res * power(sgt.query(), t);
    j = i;
    while (j < cnt && g[j].x / n == g[i].x / n) ++j;
    for (int k = i, x; k < j; ++k) {
      tem = s[x = g[k].x % n];
      tem.w[g[k].z][1] = g[k].v;
      if (k + 1 < j && g[k + 1].x == g[k].x) {
        ++k;
        tem.w[g[k].z][1] = g[k].v;
      }
      sgt.change(x, tem);
    }
    t = min(k, g[i].x / n * n + n - 1) % n;
    res = res * sgt.query(0, t);
    for (int k = i, x; k < j; ++k) {
      x = g[k].x % n;
      sgt.change(x, s[x]);
      if (k + 1 < j && g[k + 1].x == g[k].x) ++k;
    }
    i = j;
  }
  long long t = k / n - g[cnt - 1].x / n - (cnt > 1);
  if (~t) res = res * power(sgt.query(), t) * sgt.query(0, k % n);
  printf("%d\n", res.w[0][0]);
  return 0;
}
