#include <bits/stdc++.h>
using namespace std;
int N, M, P, s[50100];
long long K, ls;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  return make_pair((a.first + b.first) % P, (a.second + b.second) % P);
}
pair<int, int> operator*(pair<int, int> a, int q) {
  return make_pair(1ll * a.first * q % P, 1ll * a.second * q % P);
}
int operator*(pair<int, int> a, pair<int, int> b) {
  return (1ll * a.first * b.first + 1ll * a.second * b.second) % P;
}
pair<int, int> cur;
struct MT {
  pair<int, int> a, b;
  MT() {}
  MT(pair<int, int> _a, pair<int, int> _b) { a = _a, b = _b; }
  MT(int x, int y, int z, int r) { a = make_pair(x, y), b = make_pair(z, r); }
  pair<int, int> c() { return make_pair(a.first, b.first); }
  pair<int, int> d() { return make_pair(a.second, b.second); }
} jump[70], sm[16][50100];
pair<int, int> operator*(pair<int, int> a, MT b) {
  return make_pair(a * b.c(), a * b.d());
}
MT operator*(MT a, MT b) { return MT(a.a * b, a.b * b); }
struct exc {
  long long w;
  int v;
} e[50100];
bool cmp(exc a, exc b) { return a.w < b.w; }
void go(long long d) {
  if (d / N == ls / N) {
    for (int i = 16, _E_ = 0; i-- > _E_;)
      if (ls + (1 << i) <= d) cur = cur * sm[i][ls % N], ls += 1 << i;
    return;
  }
  long long Nx = (ls / N + 1) * N;
  for (int i = 16, _E_ = 0; i-- > _E_;)
    if (ls + (1 << i) <= Nx) cur = cur * sm[i][ls % N], ls += 1 << i;
  for (int i = 62, _E_ = 0; i-- > _E_;)
    if ((d - ls) / N >= 1ll << i) cur = cur * jump[i], ls += 1ll * N << i;
  for (int i = 16, _E_ = 0; i-- > _E_;)
    if (ls + (1 << i) <= d) cur = cur * sm[i][ls % N], ls += 1 << i;
}
int main() {
  scanf("%I64d %d", &K, &P);
  if (K == 0) {
    printf("0");
    return 0;
  }
  scanf("%d", &N);
  for (int i = 0, _E_ = N; i < _E_; ++i) scanf("%d", s + i);
  scanf("%d", &M);
  for (int i = 0, _E_ = M; i < _E_; ++i) scanf("%I64d %d", &e[i].w, &e[i].v);
  sort(e, e + M, cmp);
  jump[0] = MT(1, 0, 0, 1);
  for (int i = 0, _E_ = N; i < _E_; ++i)
    sm[0][i] = MT(s[i], 1, s[(i + N - 1) % N], 0), jump[0] = jump[0] * sm[0][i];
  for (int j = 1, _E_ = 16; j < _E_; ++j)
    for (int i = 0, _E_ = N - (1 << j) + 1; i < _E_; ++i)
      sm[j][i] = sm[j - 1][i] * sm[j - 1][i + (1 << j - 1)];
  for (int j = 1, _E_ = 62; j < _E_; ++j) jump[j] = jump[j - 1] * jump[j - 1];
  ls = 1;
  cur = make_pair(1, 0);
  for (int i = 0, _E_ = M; i < _E_; ++i) {
    if (ls == K) break;
    if (e[i].w >= K) {
      break;
    }
    go(e[i].w);
    cur =
        cur * MT(e[i].v, 1,
                 (i && e[i - 1].w == ls - 1) ? e[i - 1].v : s[(ls - 1) % N], 0);
    ++ls;
    if (ls == K) break;
    if (i == M - 1) {
      cur = cur * MT(s[ls % N], 1, e[i].v, 0);
      ++ls;
      break;
    }
    if (e[i + 1].w != ls) {
      cur = cur * MT(s[ls % N], 1, e[i].v, 0);
      ++ls;
      continue;
    }
  }
  go(K);
  printf("%d", cur.first % P);
}
