#include <bits/stdc++.h>
using namespace std;
int P;
struct Matrix {
  long long M[2][2];
  Matrix() {
    M[0][0] = 1;
    M[0][1] = 0;
    M[1][0] = 0;
    M[1][1] = 1;
  }
  Matrix(int a, int b) {
    M[0][0] = a;
    M[0][1] = b;
    M[1][0] = 1;
    M[1][1] = 0;
  }
  Matrix operator*(Matrix X) {
    Matrix ret;
    for (int i = 0; i < 2; ++i)
      for (int j = 0; j < 2; ++j)
        ret.M[i][j] = (M[i][0] * X.M[0][j] + M[i][1] * X.M[1][j]) % P;
    return ret;
  }
  Matrix pow(long long b) {
    Matrix ret, a = *this;
    while (b) {
      if (b & 1) ret = ret * a;
      a = a * a;
      b >>= 1;
    }
    return ret;
  }
};
int N, M, s[50000];
pair<long long, int> pos[50000];
Matrix T[4 * 50000];
void init(int node, int l, int r) {
  if (l == r) {
    if (l != N - 1)
      T[node].M[0][0] = s[l + 1];
    else
      T[node].M[0][0] = s[0];
    T[node].M[0][1] = s[l];
    T[node].M[1][0] = 1;
    T[node].M[1][1] = 0;
  } else {
    int mi = (l + r) >> 1;
    init(2 * node + 1, l, mi);
    init(2 * node + 2, mi + 1, r);
    T[node] = T[2 * node + 2] * T[2 * node + 1];
  }
}
Matrix query(int node, int l, int r, int x, int y) {
  if (r < x || l > y) return Matrix();
  if (x <= l && r <= y) return T[node];
  int mi = (l + r) >> 1;
  return query(2 * node + 2, mi + 1, r, x, y) *
         query(2 * node + 1, l, mi, x, y);
}
Matrix calc(long long l, long long r) {
  Matrix ret;
  if (l % N != 0) {
    int suff = N - l % N;
    if (r - l + 1 >= suff) {
      ret = query(0, 0, N - 1, l % N, N - 1);
      l += suff;
    } else
      return query(0, 0, N - 1, l % N, l % N + r - l);
  }
  if (r - l + 1 >= N) {
    ret = query(0, 0, N - 1, 0, N - 1).pow((r - l + 1) / N) * ret;
    l += (r - l + 1) / N * N;
  }
  if (l <= r) ret = query(0, 0, N - 1, 0, r % N) * ret;
  return ret;
}
long long solve(long long K) {
  if (K == 0) return 0;
  if (K == 1) return 1 % P;
  long long cur = 0;
  int p = 0;
  Matrix ret;
  while (cur + 2 <= K) {
    if (p < M && cur == pos[p].first) {
      while (cur + 2 <= K && p + 1 < M && pos[p + 1].first == cur + 1) {
        ret = Matrix(pos[p + 1].second, pos[p].second) * ret;
        ++p;
        ++cur;
      }
      if (cur + 2 <= K) {
        ret = Matrix(s[(cur + 1) % N], pos[p].second) * ret;
        ++p;
        ++cur;
      }
    } else if (p < M && cur + 1 == pos[p].first) {
      ret = Matrix(pos[p].second, s[cur % N]) * ret;
      ++cur;
    } else {
      long long end = K - 2;
      if (p < M) {
        end = min(end, pos[p].first - 2);
      }
      ret = calc(cur, end) * ret;
      cur = end + 1;
    }
  }
  return ret.M[0][0];
}
int main() {
  ios::sync_with_stdio(0);
  long long K;
  cin >> K >> P >> N;
  for (int i = 0; i < N; ++i) cin >> s[i];
  cin >> M;
  for (int i = 0; i < M; ++i) cin >> pos[i].first >> pos[i].second;
  init(0, 0, N - 1);
  sort(pos, pos + M);
  cout << solve(K) << '\n';
  return 0;
}
