#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
int MOD, n, m;
long long k;
struct Matrix {
  int a[2][2];
  void E() {
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < 2; ++j) a[i][j] = i == j ? 1 : 0;
  }
  void Z() {
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < 2; ++j) a[i][j] = 0;
  }
} tr[N << 2], tp[N], ans;
Matrix operator*(Matrix a, Matrix b) {
  Matrix c;
  c.Z();
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
        c.a[i][j] = (c.a[i][j] + 1LL * a.a[i][k] * b.a[k][j]) % MOD;
  return c;
}
void build(int k, int l, int r) {
  if (l == r) {
    tr[k] = tp[l];
    return;
  }
  int lk = k << 1, rk = k << 1 | 1, mid = (l + r) >> 1;
  build(lk, l, mid);
  build(rk, mid + 1, r);
  tr[k] = tr[rk] * tr[lk];
}
Matrix fpow(Matrix x, long long p) {
  Matrix rs;
  rs.E();
  while (p) {
    if (p & 1LL) rs = rs * x;
    x = x * x;
    p >>= 1;
  }
  return rs;
}
void modify(int p, int x, int v, int k, int l, int r) {
  if (l == r) {
    tr[k].a[1][x] = v;
    return;
  }
  int lk = k << 1, rk = k << 1 | 1, mid = (l + r) >> 1;
  if (p <= mid)
    modify(p, x, v, lk, l, mid);
  else
    modify(p, x, v, rk, mid + 1, r);
  tr[k] = tr[rk] * tr[lk];
}
Matrix query(int a, int b, int k, int l, int r) {
  Matrix rs;
  rs.E();
  if (a > r || b < l) return rs;
  if (a <= l && r <= b) return tr[k];
  int lk = k << 1, rk = k << 1 | 1, mid = (l + r) >> 1;
  return query(a, b, rk, mid + 1, r) * query(a, b, lk, l, mid);
}
pair<long long, int> s[N << 1];
long long pre = 1;
int p;
int main() {
  scanf("%lld %d", &k, &MOD);
  ans.E();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    tp[i].a[1][1] = tp[i + 1].a[1][0] = a;
  }
  tp[n].a[1][1] = tp[0].a[1][1];
  for (int i = 1; i <= n; ++i) tp[i].a[0][0] = 0, tp[i].a[0][1] = 1;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) scanf("%lld %d", &s[i].first, &s[i].second);
  sort(s, s + m);
  m *= 2;
  for (int i = m - 2; i >= 0; i -= 2) s[i] = s[i >> 1];
  for (int i = 0; i < m; i += 2) {
    s[i + 1] = s[i];
    s[i + 1].first++;
  }
  build(1, 1, n);
  int l = 0, r = 0;
  s[m].first = 2e18;
  while (pre <= k) {
    if (s[l].first < pre + n) {
      while (s[r].first < pre + n) {
        modify(s[r].first - pre + 1, (r & 1) ^ 1, s[r].second, 1, 1, n);
        r++;
      }
      ans = query(1, min(k - pre + 1, (long long)n), 1, 1, n) * ans;
      while (l < r) {
        modify(s[l].first - pre + 1, (l & 1) ^ 1,
               tp[s[l].first - pre + 1].a[1][(l & 1) ^ 1], 1, 1, n);
        l++;
      }
      pre += min(k - pre + 1, (long long)n);
    } else {
      if (k < pre + n) {
        ans = query(1, k - pre + 1, 1, 1, n) * ans;
        pre = k + 1;
      } else {
        ans = fpow(tr[1], (min(k, s[l].first - 1) - pre + 1) / n) * ans;
        pre += (min(k, s[l].first - 1) - pre + 1) / n * n;
      }
    }
  }
  printf("%d\n", ans.a[0][1]);
}
