#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int N = 1 << 16;
struct matr {
  int a, b, c, d;
};
int n;
int m;
long long K;
int mod;
matr tree[2 * N];
int s[N];
pair<long long, int> v[N];
matr full;
matr mul(matr x, matr y) {
  matr z;
  z.a = ((long long)x.a * y.a + (long long)x.b * y.c) % mod;
  z.b = ((long long)x.a * y.b + (long long)x.b * y.d) % mod;
  z.c = ((long long)x.c * y.a + (long long)x.d * y.c) % mod;
  z.d = ((long long)x.c * y.b + (long long)x.d * y.d) % mod;
  return z;
}
matr build(int x, int l, int r) {
  if (l == r) return tree[x] = {0, s[l], 1, s[l]};
  int s = (l + r) / 2;
  return tree[x] = mul(build(x * 2 + 1, l, s), build(x * 2 + 2, s + 1, r));
}
matr get(int x, int l, int r, int lc, int rc) {
  if (r < lc || l > rc) return {1, 0, 0, 1};
  if (l >= lc && r <= rc) return tree[x];
  int s = (l + r) / 2;
  return mul(get(x * 2 + 1, l, s, lc, rc), get(x * 2 + 2, s + 1, r, lc, rc));
}
matr power(matr a, long long b) {
  matr c = {1, 0, 0, 1};
  while (b) {
    if (b & 1) c = mul(c, a);
    a = mul(a, a);
    b /= 2;
  }
  return c;
}
matr skip(long long a, long long b) {
  if (a > b) return {1, 0, 0, 1};
  long long na = a / n;
  long long nb = b / n;
  long long ma = a % n;
  long long mb = b % n;
  if (na == nb) return get(0, 0, n - 1, ma, mb);
  return mul(mul(get(0, 0, n - 1, ma, n - 1), power(full, nb - na - 1)),
             get(0, 0, n - 1, 0, mb));
}
int main() {
  scanf("%I64d%d", &K, &mod);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &s[i]);
  build(0, 0, n - 1);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%I64d%d", &v[i].first, &v[i].second);
  }
  sort(v, v + m);
  matr cur = {1, 0, 0, 1};
  full = get(0, 0, n - 1, 0, n - 1);
  long long last = 0;
  K--;
  for (int i = 0; i < m; i++) {
    if (v[i].first > K) {
      cur = mul(cur, skip(last, K));
      last = K + 1;
      break;
    } else {
      cur = mul(cur, skip(last, v[i].first - 1));
      cur = mul(cur, {0, v[i].second, 1, v[i].second});
      last = v[i].first + 1;
    }
  }
  cur = mul(cur, skip(last, K));
  int ans = ((long long)cur.c + cur.d - cur.a - cur.b) % mod;
  if (ans < 0) ans += mod;
  printf("%d\n", ans);
  return 0;
}
