#include <bits/stdc++.h>
using namespace std;
long long k;
int mod, n, m;
int s[50004];
pair<long long, int> p[50004];
struct Matrix {
  int mat[2][2];
  void init() {
    memset(mat, 0, sizeof mat);
    mat[0][0] = mat[1][1] = 1;
    return;
  }
  Matrix operator*(Matrix x) {
    Matrix t;
    t.init();
    t.mat[0][0] = ((1ll * (mat[0][0]) * (x.mat[0][0]) % mod) +
                   (1ll * (mat[0][1]) * (x.mat[1][0]) % mod)) %
                  mod;
    t.mat[0][1] = ((1ll * (mat[0][0]) * (x.mat[0][1]) % mod) +
                   (1ll * (mat[0][1]) * (x.mat[1][1]) % mod)) %
                  mod;
    t.mat[1][0] = ((1ll * (mat[1][0]) * (x.mat[0][0]) % mod) +
                   (1ll * (mat[1][1]) * (x.mat[1][0]) % mod)) %
                  mod;
    t.mat[1][1] = ((1ll * (mat[1][0]) * (x.mat[0][1]) % mod) +
                   (1ll * (mat[1][1]) * (x.mat[1][1]) % mod)) %
                  mod;
    return t;
  }
  Matrix operator^(long long y) {
    Matrix t, x = *this;
    t.init();
    for (; y; y >>= 1, x = x * x)
      if (y & 1) t = t * x;
    return t;
  }
};
struct Segment_Tree {
  Matrix val[50004 << 2];
  void build(int pos, int l, int r) {
    if (l == r) {
      val[pos].mat[0][0] = 0;
      val[pos].mat[1][0] = 1;
      val[pos].mat[0][1] = s[l];
      val[pos].mat[1][1] = s[(l + 1) % n];
      return;
    }
    int mid = (l + r) >> 1;
    build(pos << 1, l, mid);
    build(pos << 1 | 1, mid + 1, r);
    return val[pos] = val[pos << 1] * val[pos << 1 | 1], void();
  }
  Matrix query(int pos, int l, int r, int nl, int nr) {
    if (l >= nl && r <= nr) return val[pos];
    int mid = (l + r) >> 1;
    Matrix ans;
    ans.init();
    if (mid >= nl) ans = ans * query(pos << 1, l, mid, nl, nr);
    if (mid < nr) ans = ans * query(pos << 1 | 1, mid + 1, r, nl, nr);
    return ans;
  }
} T;
int main() {
  cin >> k >> mod >> n;
  if (k == 0 || k == 1) return cout << k % mod << endl, 0;
  --k;
  for (int i = 0; i < n; ++i) scanf("%d", s + i), s[i] %= mod;
  T.build(1, 0, n - 1);
  cin >> m;
  Matrix ans, sum = T.val[1], tmp;
  tmp = T.query(1, 0, n - 1, n - 1, n - 1);
  ans.init();
  int cnt = 0;
  for (int i = 1; i <= m; ++i) {
    long long j;
    int v;
    scanf("%lld%d", &j, &v);
    if (j > k) continue;
    p[++cnt] = make_pair(j, v % mod);
  }
  sort(p + 1, p + 1 + cnt);
  long long lst = -1;
  for (int i = 1; i <= cnt; ++i) {
    int pos = i, l = 0;
    long long x = p[i].first / n;
    if (p[i].first != x * n)
      ans = ans * (sum ^ (x - lst - 1));
    else if (x != lst + 1) {
      ans = ans * (sum ^ (x - lst - 2));
      if (n != 1) ans = ans * T.query(1, 0, n - 1, 0, n - 2);
      Matrix o;
      o.mat[0][0] = 0;
      o.mat[1][0] = 1;
      o.mat[0][1] = s[n - 1];
      o.mat[1][1] = p[i].second;
      ans = ans * o;
    }
    lst = x;
    Matrix t;
    t.init();
    while (x == p[pos].first / n && pos <= cnt) {
      int r = p[pos].first % n;
      if (p[pos].first == k) break;
      if (l < r) {
        if (l < r - 1) t = t * T.query(1, 0, n - 1, l, r - 2);
        Matrix o;
        int tmp1, tmp2 = p[pos].second;
        if (p[pos - 1].first + 1 == p[pos].first)
          tmp1 = p[pos - 1].second;
        else
          tmp1 = s[(p[pos].first - 1 + n) % n];
        o.mat[0][0] = 0;
        o.mat[1][0] = 1;
        o.mat[0][1] = tmp1;
        o.mat[1][1] = tmp2;
        t = t * o;
      }
      Matrix x;
      int tmp1 = p[pos].second, tmp2;
      if (p[pos + 1].first == p[pos].first + 1)
        tmp2 = p[pos + 1].second;
      else
        tmp2 = s[(p[pos].first + 1) % n];
      x.mat[0][0] = 0;
      x.mat[1][0] = 1;
      x.mat[0][1] = tmp1;
      x.mat[1][1] = tmp2;
      t = t * x;
      l = r + 1;
      ++pos;
    }
    if (x == k / n) {
      int r = k % n;
      if (!r) break;
      if (l < r - 1) ans = ans * T.query(1, 0, n - 1, l, r - 2);
      if (p[pos].first == k) {
        Matrix o;
        o.mat[0][0] = 0;
        o.mat[1][0] = 1;
        o.mat[0][1] = s[(r - 2 + n) % n];
        o.mat[1][1] = p[pos].second;
        t = t * o;
      } else
        t = t * T.query(1, 0, n - 1, r - 1, r - 1);
      ans = ans * t;
      break;
    }
    if (l < n - 1) t = t * T.query(1, 0, n - 1, l, n - 2);
    if (l < n) {
      if (p[pos].first == (x + 1) * n) {
        Matrix o;
        o.mat[0][0] = 0;
        o.mat[1][0] = 1;
        o.mat[0][1] = s[n - 1];
        o.mat[1][1] = p[pos].second;
        t = t * o;
      } else
        t = t * tmp;
    }
    ans = ans * t;
    i = pos - 1;
  }
  if (k / n != lst) {
    ans = ans * (sum ^ (k / n - lst - 1));
    if (k % n) ans = ans * T.query(1, 0, n - 1, 0, k % n - 1);
  }
  cout << ans.mat[1][1] << endl;
  return 0;
}
