#include <bits/stdc++.h>
using namespace std;
struct Mat {
  int64_t a, b, c, d;
};
int64_t mod(int64_t a, int64_t b) {
  int64_t res = a % b;
  if (res < 0) res += b;
  return res;
}
int64_t N, P;
vector<vector<Mat>> cycs;
map<int64_t, int64_t> exceptions;
vector<int64_t> s;
int64_t get(int64_t n) {
  if (exceptions.find(n) != exceptions.end())
    return exceptions[n];
  else
    return s[mod(n, N)];
}
Mat operator*(Mat x, Mat y) {
  return Mat{
      (x.a * y.a % P + x.b * y.c % P) % P, (x.a * y.b % P + x.b * y.d % P) % P,
      (x.c * y.a % P + x.d * y.c % P) % P, (x.c * y.b % P + x.d * y.d % P) % P};
}
Mat cyc_product(int64_t start, int64_t end) {
  if (start > end) {
    return Mat{1, 0, 0, 1};
  }
  int64_t nxt = 1;
  int64_t l = 0;
  while (start + nxt - 1 <= end) {
    nxt *= 2;
    l++;
  }
  nxt /= 2;
  l--;
  return cycs[l][end % N] * cyc_product(start, end - nxt);
}
int main(void) {
  int64_t M, K;
  cin >> K >> P;
  cin >> N;
  for (int64_t i = 0; i < N; i++) {
    int64_t foo;
    cin >> foo;
    s.push_back(foo % P);
  }
  cin >> M;
  for (int64_t i = 0; i < M; i++) {
    int64_t j, v;
    cin >> j >> v;
    if (j < K) exceptions[j] = v;
  }
  if (K == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (K == 1) {
    cout << 1 % P << endl;
    return 0;
  }
  if (K == 2) {
    cout << get(1) % P << endl;
    return 0;
  }
  if (K == 3) {
    cout << (get(2) * get(1) + get(1)) % P << endl;
    return 0;
  }
  cycs.push_back(vector<Mat>(N, Mat{0, 0, 0, 0}));
  for (int64_t i = 0; i < N; i++) {
    cycs[0][i] = Mat{0, 1, s[mod(i - 2, N)], s[mod(i - 1, N)]};
  }
  for (int64_t l = 1; ((int64_t)1 << l) <= K; l++) {
    cycs.push_back(vector<Mat>(N, Mat{0, 0, 0, 0}));
    for (int64_t i = 0; i < N; i++) {
      cycs[l][i] =
          cycs[l - 1][i] * cycs[l - 1][mod(i - ((int64_t)1 << (l - 1)), N)];
    }
  }
  set<int64_t> bads;
  for (auto e : exceptions) {
    if (e.first + 1 <= K) bads.insert(e.first + 1);
    if (e.first + 2 <= K) bads.insert(e.first + 2);
  }
  Mat prod = Mat{1, 0, 0, 1};
  int64_t start = 2;
  for (auto end : bads) {
    if (end < 2) continue;
    prod = Mat{0, 1, get(end - 2), get(end - 1)} * cyc_product(start, end - 1) *
           prod;
    start = end + 1;
  }
  prod = cyc_product(start, K) * prod;
  cout << prod.d % P << endl;
  return 0;
}
