#include <bits/stdc++.h>
using namespace std;
long long K;
int P, N, M, S[50005];
struct Mat {
  int A[2][2];
  Mat() { memset(A, 0, sizeof(A)); }
  void Init() { A[0][0] = A[1][1] = 1; }
  void New(long long x) {
    A[1][0] = 1;
    A[0][1] = S[(x - 2 + N) % N];
    A[1][1] = S[(x - 1 + N) % N];
  }
  Mat operator*(const Mat& b) {
    Mat c, a = *this;
    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] = (1ll * a.A[i][k] * b.A[k][j] + c.A[i][j]) % P;
    return c;
  }
  Mat operator^(long long k) {
    Mat a = *this, ret;
    ret.Init();
    for (; k; k >>= 1, a = a * a)
      if (k & 1) ret = ret * a;
    return ret;
  }
} T[50005 << 2], Ans;
map<long long, Mat> G;
void Build(int u, int l, int r) {
  if (l == r) {
    T[u].New(l);
    return;
  }
  int Mid = l + r >> 1;
  Build(u << 1, l, Mid);
  Build(u << 1 | 1, Mid + 1, r);
  T[u] = T[u << 1] * T[u << 1 | 1];
}
Mat Query(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) return T[u];
  int Mid = l + r >> 1;
  if (y <= Mid) return Query(u << 1, l, Mid, x, y);
  if (x > Mid) return Query(u << 1 | 1, Mid + 1, r, x, y);
  return Query(u << 1, l, Mid, x, y) * Query(u << 1 | 1, Mid + 1, r, x, y);
}
Mat Work(long long l, long long r) {
  if (l / N == r / N) return Query(1, 0, N - 1, l % N, r % N);
  return Query(1, 0, N - 1, l % N, N - 1) *
         (Query(1, 0, N - 1, 0, N - 1) ^ (r / N - l / N - 1)) *
         Query(1, 0, N - 1, 0, r % N);
}
int main() {
  scanf("%I64d%d%d", &K, &P, &N);
  if (K < 2) return printf("%d\n", K % P), 0;
  for (int i = 0; i < N; i++) scanf("%d", &S[i]);
  scanf("%d", &M);
  for (int i = 0; i < M; i++) {
    long long x;
    int k;
    scanf("%I64d%d", &x, &k);
    if (!G.count(x + 1)) G[x + 1].New(x + 1);
    G[x + 1].A[1][1] = k;
    if (!G.count(x + 2)) G[x + 2].New(x + 2);
    G[x + 2].A[0][1] = k;
  }
  Build(1, 0, N - 1);
  Ans.Init();
  long long Now = 1;
  for (map<long long, Mat>::iterator i = G.begin(); i != G.end(); i++) {
    long long x = i->first;
    Mat k = i->second;
    if (K < x) {
      Ans = Ans * Work(Now + 1, K), Now = K;
      break;
    } else {
      if (Now + 1 <= x - 1) Ans = Ans * Work(Now + 1, x - 1);
      Ans = Ans * k;
      Now = x;
      if (K == x) break;
    }
  }
  if (Now < K) Ans = Ans * Work(Now + 1, K);
  printf("%d\n", Ans.A[1][1]);
}
