#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long n, K, P;
struct matrix {
  long long a[2][2];
  matrix() { memset(a, 0, sizeof(a)); }
  inline bool operator==(const matrix& rhs) const {
    return a[0][0] == rhs.a[0][0] && a[0][1] == rhs.a[0][1] &&
           a[1][0] == rhs.a[1][0] && a[1][1] == rhs.a[1][1];
  }
  inline bool operator!=(const matrix& rhs) const { return !(*this == rhs); }
  inline matrix operator*(const matrix& rhs) const {
    matrix ret;
    for (int i = 0; i <= 1; i++) {
      for (int j = 0; j <= 1; j++) {
        for (int k = 0; k <= 1; k++) {
          ret.a[i][j] += a[i][k] * rhs.a[k][j];
        }
        ret.a[i][j] %= P;
      }
    }
    return ret;
  }
  inline void print() {
    for (int i = 0; i <= 1; i++) {
      for (int j = 0; j <= 1; j++) {
        printf("%d", a[i][j]);
      }
      puts("");
    }
  }
};
matrix null;
inline matrix power(matrix A, long long B) {
  matrix ret;
  ret.a[0][0] = 1;
  ret.a[1][1] = 1;
  while (B) {
    if (B & 1) ret = ret * A;
    A = A * A;
    B >>= 1;
  }
  return ret;
}
inline matrix get_matrix(long long a, long long b) {
  matrix ret;
  ret.a[1][0] = 1;
  ret.a[0][1] = a;
  ret.a[1][1] = b;
  return ret;
}
map<long long, long long> spe;
long long s[1000010];
inline long long get_val(long long x) {
  if (spe.count(x)) return spe[x];
  return s[x % n];
}
matrix q[1000010];
inline void build(int l, int r, int o) {
  if (l == r) {
    q[o] = get_matrix(s[l], s[l + 1]);
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, 2 * o);
  build(mid + 1, r, 2 * o + 1);
  q[o] = q[2 * o] * q[2 * o + 1];
}
inline matrix query(int l, int r, int o, int x, int y) {
  if (x <= l && r <= y) {
    return q[o];
  }
  int mid = (l + r) / 2;
  matrix ls, rs;
  if (x <= mid) ls = query(l, mid, 2 * o, x, y);
  if (y > mid) rs = query(mid + 1, r, 2 * o + 1, x, y);
  if (ls != null && rs != null) return ls * rs;
  return ls != null ? ls : rs;
}
pair<long long, matrix> abnormal[1000010];
int tot;
inline matrix getans(long long l, long long r) {
  matrix ret;
  if (r - l >= n) {
    long long k = (r - l) / n, st = (r - l) % n;
    matrix A = query(0, 2 * n - 1, 1, l % n, l % n + n - 1);
    ret = power(A, k);
    if (st) ret = ret * query(0, 2 * n - 1, 1, r % n + n - st, r % n + n - 1);
  } else {
    if (l % n < r % n)
      ret = query(0, 2 * n - 1, 1, l % n, r % n - 1);
    else
      ret = query(0, 2 * n - 1, 1, l % n, r % n + n - 1);
  }
  return ret;
}
int main() {
  K = read(), P = read();
  if (P == 1) {
    return puts("0"), 0;
  }
  n = read();
  for (int i = 0; i < n; i++) {
    s[i] = read();
    s[i + n] = s[i];
  }
  s[2 * n] = s[0];
  build(0, 2 * n - 1, 1);
  int m = read();
  for (int i = 1; i <= m; i++) {
    long long u = read(), v = read();
    spe[u] = v;
  }
  tot = -1;
  for (map<long long, long long>::iterator it = spe.begin(); it != spe.end();
       it++) {
    if (!(tot && abnormal[tot].first == it->first - 1)) {
      if (it->first - 1 < K - 1) {
        abnormal[++tot] = make_pair(
            it->first - 1, get_matrix(get_val(it->first - 1), it->second));
      }
    }
    if (it->first < K - 1) {
      abnormal[++tot] =
          make_pair(it->first, get_matrix(it->second, get_val(it->first + 1)));
    }
  }
  if (K) {
    abnormal[++tot] = make_pair(K - 1, get_matrix(get_val(K - 1), get_val(K)));
  }
  matrix cur;
  cur.a[0][0] = 1;
  cur.a[1][1] = 1;
  for (int i = 0; i <= tot; i++) {
    long long last = i ? abnormal[i - 1].first + 1 : 0ll;
    if (abnormal[i].first > last) {
      cur = cur * getans(last, abnormal[i].first);
    }
    cur = cur * abnormal[i].second;
  }
  printf("%d\n", cur.a[1][0]);
  return 0;
}
