#include <bits/stdc++.h>
using namespace std;
int scand() {
  int x;
  assert(scanf("%d", &x) == 1);
  return x;
}
long long scanlld() {
  long long x;
  assert(scanf("%I64d", &x) == 1);
  return x;
}
int scans(char *w) {
  assert(scanf("%s", w) == 1);
  return strlen(w);
}
struct matrix {
  int m[2][2];
  matrix() {
    for (int i = 0; i < (2); i++)
      for (int j = 0; j < (2); j++) m[i][j] = 0;
  }
  matrix(int a, int b, int c, int d) {
    m[0][0] = a;
    m[0][1] = b;
    m[1][0] = c;
    m[1][1] = d;
  }
};
matrix I = matrix(1, 0, 0, 1);
ostream &operator<<(ostream &out, matrix m) {
  return out << m.m[0][0] << " " << m.m[0][1] << " " << m.m[1][0] << " "
             << m.m[1][1];
}
template <class A, class B>
ostream &operator<<(ostream &out, pair<A, B> p) {
  return out << p.first << ", " << p.second;
}
const int N = 5e4;
const int M = 5e4;
int n, m, p;
long long k;
int s[N];
map<long long, int> diffs;
matrix mul(matrix a, matrix b) {
  matrix c;
  for (int i = 0; i < (2); i++)
    for (int j = 0; j < (2); j++)
      for (int k = 0; k < (2); k++) {
        c.m[i][j] += ((long long)a.m[i][k] * b.m[k][j]) % p;
        c.m[i][j] %= p;
      }
  return c;
}
int get_s(long long j) {
  if (diffs.count(j)) return diffs[j];
  return s[j % n];
}
map<pair<int, int>, matrix> _range_product_i;
matrix range_product_i(int i, int j) {
  assert(i < j);
  pair<int, int> ij = make_pair(i, j);
  if (_range_product_i.count(ij)) return _range_product_i[ij];
  matrix m;
  if (i + 1 == j) {
    m.m[0][0] = 0;
    m.m[0][1] = 1;
    m.m[1][0] = s[(i) % n];
    m.m[1][1] = s[(i + 1) % n];
  } else {
    int mid = (i + j) / 2;
    m = mul(range_product_i(mid, j), range_product_i(i, mid));
  }
  if (0)
    cout << "i"
         << " = " << i << endl;
  if (0)
    cout << "j"
         << " = " << j << endl;
  if (0)
    cout << "m"
         << " = " << m << endl;
  return _range_product_i[ij] = m;
}
matrix range_product(long long i, long long j) {
  assert(i <= j);
  if (i == j) return I;
  auto lb = diffs.lower_bound(i);
  auto ub = diffs.upper_bound(j);
  matrix a;
  if (lb == ub) {
    int ii = i % n;
    int jj = (j % n == 0) ? n : j % n;
    a = range_product_i(ii, jj);
  } else if (i + 1 == j) {
    a = matrix(0, 1, get_s(i), get_s(j));
  } else {
    long long mid = (i + j) / 2;
    if (0)
      cout << "i"
           << " = " << i << endl;
    if (0)
      cout << "mid"
           << " = " << mid << endl;
    if (0)
      cout << "j"
           << " = " << j << endl;
    a = mul(range_product(mid, j), range_product(i, mid));
  }
  if (0)
    cout << "i"
         << " = " << i << endl;
  if (0)
    cout << "j"
         << " = " << j << endl;
  if (0)
    cout << "a"
         << " = " << a << endl;
  return a;
}
matrix fast_power(long long d) {
  matrix m = I;
  matrix p = range_product_i(0, n);
  if (0)
    cout << "p"
         << " = " << p << endl;
  for (int i = 0; i < 64; i++) {
    if ((d >> i) & 1) m = mul(m, p);
    p = mul(p, p);
  }
  return m;
}
int main() {
  k = scanlld();
  p = scand();
  n = scand();
  if (0)
    cout << "n"
         << " = " << n << endl;
  for (int i = 0; i < (n); i++) s[i] = scand();
  m = scand();
  if (0)
    cout << "m"
         << " = " << m << endl;
  for (int i = 0; i < (m); i++) {
    long long j = scanlld();
    int v = scand();
    diffs[j] = v;
  }
  if (0)
    cout << "p"
         << " = " << p << endl;
  for (int i = 0; i < (k); i++) {
  }
  set<long long> corrupted;
  for (auto kv : diffs) {
    if (0)
      cout << "kv"
           << " = " << kv << endl;
    if (kv.first < n) {
      if (0)
        cout << "kv.first"
             << " = " << kv.first << endl;
      return 0;
    }
    corrupted.insert(kv.first / n);
    corrupted.insert((kv.first - 1) / n);
  }
  if (0)
    cout << "\"mama\""
         << " = "
         << "mama" << endl;
  long long last_corrupted = -1;
  matrix res = I;
  for (long long c : corrupted)
    if (c < k / n) {
      if (0)
        cout << "c"
             << " = " << c << endl;
      matrix m1 = fast_power(c - (last_corrupted + 1));
      if (0)
        cout << "m1"
             << " = " << m1 << endl;
      res = mul(m1, res);
      matrix m2 = range_product((long long)c * n, (long long)(c + 1) * n);
      if (0)
        cout << "m2"
             << " = " << m2 << endl;
      res = mul(m2, res);
      last_corrupted = c;
    }
  res = mul(fast_power(k / n - (last_corrupted + 1)), res);
  res = mul(range_product((k / n) * n, k), res);
  printf("%d\n", res.m[0][1]);
}
