#include <bits/stdc++.h>
using namespace std;
const int NN = 50000 + 117;
const int MM = 50000 + 117;
long long read() {
  long long fl = 1, x;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    fl = -1;
    c = getchar();
  }
  for (x = 0; c >= '0' && c <= '9'; c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  return x * fl;
}
void open() { freopen("a.in", "r", stdin); }
void close() {
  fclose(stdin);
  fclose(stdout);
}
int m, n;
int mod;
long long k;
long long s[NN] = {};
struct mat {
  long long a[2][2];
  void unit() {
    a[0][0] = a[1][1] = 1;
    a[0][1] = a[1][0] = 0;
  }
  void clear() { memset(a, 0, sizeof a); }
  void get(int id) {
    a[0][0] = 0;
    a[0][1] = s[id];
    a[1][0] = 1;
    a[1][1] = s[id + 1];
  }
  mat operator*(mat x) {
    mat tp;
    tp.clear();
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 2; ++j) {
        for (int k = 0; k < 2; ++k) {
          tp.a[i][j] += a[i][k] * x.a[k][j];
        }
        tp.a[i][j] %= mod;
      }
    }
    return tp;
  }
} t[NN * 4];
mat ksm(mat a, long long b) {
  mat res;
  res.unit();
  for (; b; b >>= 1, a = a * a)
    if (b & 1) res = res * a;
  return res;
}
struct node {
  long long pos;
  int id;
  int v;
} p[2 * NN] = {};
bool cmp(node a, node b) { return a.pos < b.pos; }
node st[2 * NN] = {};
int top = 0;
mat ans;
mat all;
void pup(int pos) { t[pos] = t[pos << 1] * t[pos << 1 | 1]; }
void build(int l, int r, int pos) {
  if (l == r) {
    t[pos].get(l);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, pos << 1);
  build(mid + 1, r, pos << 1 | 1);
  pup(pos);
}
void modify(int tar, int id, long long v, int l, int r, int pos) {
  if (l == r) {
    t[pos].a[id][1] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (tar <= mid)
    modify(tar, id, v, l, mid, pos << 1);
  else
    modify(tar, id, v, mid + 1, r, pos << 1 | 1);
  pup(pos);
}
int main() {
  k = read(), mod = read();
  if (k <= 1) {
    printf("%lld\n", k % mod);
    return 0;
  }
  n = read();
  for (int i = 0; i < n; ++i) {
    s[i] = read();
  }
  s[n] = s[0];
  int m = read();
  for (int i = 1; i <= m; ++i) {
    long long pos = read(), v = read();
    p[2 * i - 1].pos = pos;
    p[2 * i - 1].id = 0;
    p[2 * i - 1].v = v;
    p[2 * i].pos = pos - 1;
    p[2 * i].id = 1;
    p[2 * i].v = v;
  }
  int qcnt = 2 * m;
  ++qcnt;
  p[qcnt].pos = 1e18 + 10;
  p[qcnt].id = 0;
  p[qcnt].v = 0;
  sort(p + 1, p + 1 + qcnt, cmp);
  build(0, n - 1, 1);
  all = t[1];
  long long pre = -1;
  ans.unit();
  long long las = k / n;
  for (int i = 1; i <= qcnt; ++i) {
    long long id = p[i].pos / n;
    if (id >= las) {
      long long gap = las - pre - 1;
      if (pre != -1) {
        ans = ans * t[1];
      }
      ans = ans * ksm(all, gap);
      int cur = i;
      for (long long now = n * las; now < k; ++now) {
        while (p[cur].pos < now) ++cur;
        mat tp;
        tp.get(now % n);
        while (p[cur].pos == now) {
          int id = p[cur].id;
          long long v = p[cur].v;
          tp.a[id][1] = v;
          ++cur;
        }
        ans = ans * tp;
      }
      break;
    } else {
      if (id != pre) {
        long long gap = id - pre - 1;
        if (pre != -1) {
          ans = ans * t[1];
          while (top) {
            --top;
            modify(st[top].pos, st[top].id, s[st[top].pos + st[top].id], 0,
                   n - 1, 1);
          }
        }
        ans = ans * ksm(all, gap);
      }
      modify(p[i].pos % n, p[i].id, p[i].v, 0, n - 1, 1);
      st[top].pos = p[i].pos % n, st[top].id = p[i].id;
      ++top;
      pre = id;
    }
  }
  long long op = ans.a[1][0];
  op = (op + mod) % mod;
  printf("%lld\n", op);
  close();
  return 0;
}
