#include <bits/stdc++.h>
using namespace std;
int n, m, MOD;
long long k;
int s[50000];
long long ind[50001], tmp[50000];
int val[50001], ord[50000];
int mu[16][50000][2][2];
int po[60][2][2];
int mtmp[2][2];
int vec[2], nvec[2];
const long long MX = 1e18;
void koef(int (&m)[2][2], int a, int b) {
  a %= MOD;
  b %= MOD;
  m[0][0] = 0;
  m[1][0] = 1;
  m[0][1] = a;
  m[1][1] = b;
}
void matMul(int (&m)[2][2], int (&a)[2][2], int (&b)[2][2]) {
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(2); ++j) {
      long long val = 0;
      for (int k = 0; k < (int)(2); ++k) val += (long long)a[i][k] * b[k][j];
      m[i][j] = val % MOD;
    }
}
void matMul(int (&m)[2][2], int (&a)[2][2]) {
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(2); ++j) {
      long long val = 0;
      for (int k = 0; k < (int)(2); ++k) val += (long long)m[i][k] * a[k][j];
      mtmp[i][j] = val % MOD;
    }
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(2); ++j) m[i][j] = mtmp[i][j];
}
void vecMul(int (&m)[2][2]) {
  for (int i = 0; i < (int)(2); ++i) {
    long long val = 0;
    for (int j = 0; j < (int)(2); ++j) val += (long long)vec[j] * m[j][i];
    nvec[i] = val % MOD;
  }
  for (int i = 0; i < (int)(2); ++i) vec[i] = nvec[i];
}
inline bool cmp(const int &lhs, const int &rhs) { return ind[lhs] < ind[rhs]; }
int main() {
  scanf("%I64d%d%d", &k, &MOD, &n);
  if (k < 2) {
    if (k == 0)
      printf("0\n");
    else
      printf("%d\n", 1 % MOD);
    return 0;
  }
  for (int i = 0; i < (int)(n); ++i) scanf("%d", s + i);
  scanf("%d", &m);
  for (int i = 0; i < (int)(m); ++i) scanf("%I64d%d", ind + i, val + i);
  for (int i = 0; i < (int)(m); ++i) ord[i] = i;
  sort(ord, ord + m, cmp);
  for (int i = 0; i < (int)(m); ++i) tmp[i] = ind[ord[i]];
  for (int i = 0; i < (int)(m); ++i) ind[i] = tmp[i];
  for (int i = 0; i < (int)(m); ++i) tmp[i] = val[ord[i]];
  for (int i = 0; i < (int)(m); ++i) val[i] = tmp[i];
  ind[m++] = 1e18 + 15;
  koef(mu[0][0], s[(2 * n - 2) % n], s[(2 * n - 1) % n]);
  koef(mu[0][1], s[(2 * n - 1) % n], s[0]);
  for (int i = 2; i < n; ++i) koef(mu[0][i], s[i - 2], s[i - 1]);
  for (int i = 0; i < 15; ++i)
    for (int j = 0; j < (int)(n); ++j) {
      matMul(mu[i + 1][j], mu[i][j], mu[i][(j + (1 << i)) % n]);
    }
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(2); ++j) po[0][i][j] = i == j;
  int w = 0;
  for (int i = 15; i >= 0; --i)
    if (w + (1 << i) <= n) {
      matMul(po[0], mu[i][w]);
      w += 1 << i;
    }
  for (int i = 1; i < 60; ++i) {
    matMul(po[i], po[i - 1], po[i - 1]);
  }
  long long pos = 2;
  int bad = 0;
  vec[0] = 0, vec[1] = 1 % MOD;
  int maxDeg = 0;
  while (((long long)n << (maxDeg + 1)) <= MX) ++maxDeg;
  while (pos <= k) {
    long long ok = min(k, ind[bad]) + 1;
    if (ok != pos) {
      if (ok - pos > 3 * n) {
        long long targ = pos - pos % n;
        if (targ < pos) targ += n;
        for (int i = 15; i >= 0; --i)
          if (targ - pos >= (1 << i)) {
            vecMul(mu[i][pos % n]);
            pos += 1 << i;
          }
        for (int i = maxDeg; i >= 0; --i)
          if (ok - pos >= ((long long)n << i)) {
            vecMul(po[i]);
            pos += (long long)n << i;
          }
      }
      while (ok - pos >= (1 << 15)) {
        vecMul(mu[15][pos % n]);
        pos += 1 << 15;
      }
      for (int i = 14; i >= 0; --i)
        if (ok - pos >= (1 << i)) {
          vecMul(mu[i][pos % n]);
          pos += 1 << i;
        }
    }
    if (pos > k) break;
    int a = s[(pos - 2) % n];
    int b = val[bad];
    int tmp = vec[1];
    vec[1] = ((long long)vec[0] * a + (long long)vec[1] * b) % MOD;
    vec[0] = tmp;
    ++pos, ++bad;
    if (pos > k) break;
    while (ind[bad] - 1 == ind[bad - 1]) {
      a = val[bad - 1];
      b = val[bad];
      tmp = vec[1];
      vec[1] = ((long long)vec[0] * a + (long long)vec[1] * b) % MOD;
      vec[0] = tmp;
      ++pos, ++bad;
      if (pos > k) break;
    }
    if (pos > k) break;
    a = val[bad - 1];
    b = s[(pos - 1) % n];
    tmp = vec[1];
    vec[1] = ((long long)vec[0] * a + (long long)vec[1] * b) % MOD;
    vec[0] = tmp;
    ++pos;
  }
  printf("%d\n", vec[1] % MOD);
  return 0;
}
