#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T, class U>
inline void print(T first, U second) {
  printsp(first);
  println(second);
}
template <class T, class U, class V>
inline void print(T first, U second, V z) {
  printsp(first);
  printsp(second);
  println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int p, m, n;
int first[50050 << 2][2][2], s[50050], v[50050], id[50050];
long long a[50050];
void push_up(int u) {
  first[u][0][0] = ((long long)first[u << 1 | 1][0][0] * first[u << 1][0][0] +
                    (long long)first[u << 1 | 1][0][1] * first[u << 1][1][0]) %
                   p;
  first[u][0][1] = ((long long)first[u << 1 | 1][0][0] * first[u << 1][0][1] +
                    (long long)first[u << 1 | 1][0][1] * first[u << 1][1][1]) %
                   p;
  first[u][1][0] = ((long long)first[u << 1 | 1][1][0] * first[u << 1][0][0] +
                    (long long)first[u << 1 | 1][1][1] * first[u << 1][1][0]) %
                   p;
  first[u][1][1] = ((long long)first[u << 1 | 1][1][0] * first[u << 1][0][1] +
                    (long long)first[u << 1 | 1][1][1] * first[u << 1][1][1]) %
                   p;
}
void build(int u, int L, int R) {
  if (L + 1 == R) {
    first[u][0][0] = s[L % n];
    first[u][0][1] = s[(L - 1) % n];
    first[u][1][0] = 1;
    first[u][1][1] = 0;
    return;
  }
  build(u << 1, L, (L + R >> 1));
  build(u << 1 | 1, (L + R >> 1), R);
  push_up(u);
}
bool cmp(int u, int v) { return a[u] > a[v]; }
map<long long, int> val, mp;
int get_val(long long second) {
  if (val.count(second)) return val[second];
  return s[second % n];
}
int ans[2][2];
int tp[2][2];
void multi(int a[2][2], int b[2][2], int c[2][2]) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      for (int k = tp[i][j] = 0; k < 2; k++)
        tp[i][j] += (long long)a[i][k] * b[k][j] % p;
    }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) c[i][j] = tp[i][j] % p;
}
void calc_p(long long n) {
  int b[2][2];
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) b[i][j] = first[1][i][j];
  while (n) {
    if (n & 1) multi(ans, b, ans);
    multi(b, b, b);
    n >>= 1;
  }
}
void calc(int u, int L, int R, int ed, int st) {
  if (L >= ed || st >= R) return;
  if (st <= L && R <= ed) {
    multi(ans, first[u], ans);
    return;
  }
  calc(u << 1 | 1, (L + R >> 1), R, ed, st);
  calc(u << 1, L, (L + R >> 1), ed, st);
}
void calc(long long R, long long L) {
  if (R < L) return;
  long long RR = R / n * n, LL = (L + n - 1) / n * n;
  if (RR > LL) {
    calc(1, 1, n + 1, R % n + 1, 1);
    calc_p((RR - LL) / n);
    calc(1, 1, n + 1, n + 1, L % n == 0 ? n : L % n);
  } else if (RR == LL) {
    calc(1, 1, n + 1, R % n + 1, 1);
    calc(1, 1, n + 1, n + 1, L % n == 0 ? n : L % n);
  } else {
    calc(1, 1, n + 1, R % n + 1, L % n);
  }
}
void mul(int u, int v) {
  tp[0][0] = ((long long)ans[0][0] * u + ans[0][1]) % p;
  tp[0][1] = ((long long)ans[0][0] * v) % p;
  tp[1][0] = ((long long)ans[1][0] * u + ans[1][1]) % p;
  tp[1][1] = ((long long)ans[1][0] * v) % p;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) ans[i][j] = tp[i][j];
}
int main() {
  long long K;
  gn(K, p);
  if (K < 2) {
    println(K % p);
    return 0;
  }
  gn(n);
  for (int i = 0; i < n; i++) gn(s[i]);
  s[n] = s[0];
  gn(m);
  for (int i = 0; i < m; i++) gn(a[i], v[i]), id[i] = i, val[a[i]] = v[i];
  build(1, 1, n + 1);
  sort(id, id + m, cmp);
  ans[0][0] = ans[1][1] = 1;
  long long pre = K + 1;
  for (int i = 0; i < m; i++) {
    long long u = a[id[i]];
    if (u > K) continue;
    calc(pre - 1, u + 2);
    if (!mp.count(u + 1) && u < K) {
      mul(get_val(u + 1), get_val(u));
    }
    mul(get_val(u), get_val(u - 1));
    mp[u] = 1;
    pre = u;
  }
  calc(pre - 1, 1);
  println(ans[1][0]);
  return 0;
}
