#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
long long K, mod, s[50011];
int n, m;
struct matrix {
  long long a[2][2];
  void clear() { memset(a, 0, sizeof(a)); }
  matrix() { clear(); }
  void set1() {
    a[0][0] = a[1][1] = 1;
    a[0][1] = a[1][0] = 0;
  }
  matrix operator*(const matrix &t) {
    matrix res;
    res.a[0][0] = (a[0][0] * t.a[0][0] + a[0][1] * t.a[1][0]) % mod;
    res.a[0][1] = (a[0][0] * t.a[0][1] + a[0][1] * t.a[1][1]) % mod;
    res.a[1][0] = (a[1][0] * t.a[0][0] + a[1][1] * t.a[1][0]) % mod;
    res.a[1][1] = (a[1][0] * t.a[0][1] + a[1][1] * t.a[1][1]) % mod;
    return res;
  }
  void db() {
    cout << "{" << a[0][0] << "," << a[0][1] << "," << a[1][0] << "," << a[1][1]
         << "}" << endl;
  }
} mt[50011], all;
pair<long long, long long> q[50011];
struct SGT {
  struct node {
    int l, r;
    matrix v;
  } a[200011];
  void build(int l, int r, int p = 1) {
    a[p].l = l;
    a[p].r = r;
    if (l == r) {
      a[p].v = mt[l];
      return;
    }
    int m = l + r >> 1;
    build(l, m, (p << 1));
    build(m + 1, r, (p << 1 | 1));
    a[p].v = a[(p << 1)].v * a[(p << 1 | 1)].v;
  }
  matrix query(int x, int y, int p = 1) {
    int l = a[p].l, r = a[p].r;
    if (x <= l && r <= y) return a[p].v;
    int m = l + r >> 1;
    matrix ans;
    ans.set1();
    if (x <= m) ans = ans * query(x, y, (p << 1));
    if (m < y) ans = ans * query(x, y, (p << 1 | 1));
    return ans;
  }
} sgt;
matrix kissme(matrix x, long long k) {
  matrix ans;
  ans.set1();
  while (k > 0) {
    if (k & 1) ans = ans * x;
    x = x * x;
    k >>= 1;
  }
  return ans;
}
matrix go(long long x, long long y) {
  matrix ans;
  ans.set1();
  if (x > y) return ans;
  if (x / n != y / n) {
    ans = ans * sgt.query(x % n, n - 1);
    x += n - x % n;
    ans = ans * kissme(all, (y - x) / n);
    x += (y - x) / n * n;
  }
  ans = ans * sgt.query(x % n, y % n);
  return ans;
}
int main() {
  K = getnum(), mod = getnum();
  n = getnum();
  if (K == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) s[i] = getnum();
  m = getnum();
  for (int i = 0; i < m; i++) q[i].first = getnum(), q[i].second = getnum();
  sort(q, q + m);
  all.set1();
  mt[0].a[0][0] = s[0];
  mt[0].a[1][0] = s[n - 1];
  mt[0].a[0][1] = 1;
  all = all * mt[0];
  for (int i = 1; i < n; i++) {
    mt[i].a[0][0] = s[i];
    mt[i].a[1][0] = s[i - 1];
    mt[i].a[0][1] = 1;
    all = all * mt[i];
  }
  sgt.build(0, n - 1);
  long long cur = 1;
  matrix ans;
  ans.set1();
  for (int i = 0; i < m; i++) {
    long long x = q[i].first;
    if (x >= K) {
      ans = ans * go(cur, K - 1);
      cur = K;
      break;
    }
    ans = ans * go(cur, x - 1);
    cur = x;
    matrix tmp = mt[x % n];
    tmp.a[0][0] = q[i].second;
    if (i > 0 && q[i - 1].first + 1 == x) tmp.a[1][0] = q[i - 1].second;
    ans = ans * tmp;
    cur++;
    if ((i == m - 1 || i + 1 < m && cur < q[i + 1].first) && cur < K) {
      tmp = mt[cur % n];
      tmp.a[1][0] = q[i].second;
      ans = ans * tmp;
      cur++;
    }
  }
  if (cur < K) ans = ans * go(cur, K - 1), cur = K;
  putnum(ans.a[0][0] % mod), putendl();
  return 0;
}
