#include <bits/stdc++.h>
using namespace std;
long long k;
int mod;
vector<vector<int> > mul(const vector<vector<int> >& a,
                         const vector<vector<int> >& b) {
  vector<vector<int> > res = a;
  for (int i = (0); i < (res.size()); ++i) {
    for (int j = (0); j < (res.size()); ++j) {
      long long sum = 0;
      for (int k = (0); k < (res.size()); ++k) {
        sum += a[i][k] * 1ll * b[k][j];
        sum %= mod;
      }
      res[i][j] = sum;
    }
  }
  return res;
}
vector<vector<int> > t[200100];
inline vector<vector<int> > get(int l, int r, int L, int R, int v) {
  if ((l == L) && (r == R)) {
    return t[v];
  }
  int m = (L + R) / 2;
  if (r <= m) return get(l, r, L, m, v + v);
  if (l > m) return get(l, r, m + 1, R, v + v + 1);
  vector<vector<int> > res1 = get(l, m, L, m, v + v);
  vector<vector<int> > res2 = get(m + 1, r, m + 1, R, v + v + 1);
  return mul(res1, res2);
}
vector<pair<long long, int> > f;
int s[50010];
vector<vector<int> > one;
pair<long long, int> q[50010];
set<long long> need;
map<long long, long long> bad;
vector<vector<int> > bp(vector<vector<int> >& a, long long p) {
  if (p == 0) return one;
  vector<vector<int> > res = bp(a, p / 2);
  res = mul(res, res);
  if (p & 1) res = mul(res, a);
  return res;
}
int n;
inline void getSimple(long long idx) {
  long long last = f.back().first;
  for (long long i = last + 1; i <= idx; ++i) {
    long long s1 = s[(i - 1) % n];
    if (bad.find(i - 1) != bad.end()) s1 = bad[i - 1];
    long long s2 = s[(i - 2) % n];
    if (bad.find(i - 2) != bad.end()) s2 = bad[i - 2];
    long long f1 = f[f.size() - 1].second;
    long long f2 = f[f.size() - 2].second;
    f.push_back(make_pair(i, (f1 * s1 + f2 * s2) % mod));
  }
}
vector<vector<int> > pre[50010];
vector<vector<int> > suf[50010];
int main() {
  cin >> k >> mod;
  need.insert(k);
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &s[i]);
    s[i] %= mod;
  }
  one = {{1 % mod, 0}, {0, 1 % mod}};
  int K = 1;
  while (K < n) K += K;
  for (int i = (0); i < (n); ++i) {
    t[K + i] = {{0, (int)s[i] % mod}, {1 % mod, (int)s[(i + 1) % n] % mod}};
  }
  for (int i = (n); i < (K); ++i) {
    t[K + i] = one;
  }
  for (int i = K - 1; i > 0; --i) t[i] = mul(t[i + i], t[i + i + 1]);
  for (int i = (0); i < (n); ++i) {
    pre[i] = {{0, (int)s[i] % mod}, {1 % mod, (int)s[(i + 1) % n] % mod}};
  }
  for (int i = (1); i < (n); ++i) {
    pre[i] = mul(pre[i - 1], pre[i]);
  }
  int m;
  scanf("%d", &m);
  for (int i = (0); i < (m); ++i) {
    scanf("%I64d%d", &q[i].first, &q[i].second);
    need.insert(q[i].first + 1);
    need.insert(q[i].first + 2);
    bad[q[i].first] = (q[i].second % mod);
  }
  f.push_back(make_pair(0, 0));
  f.push_back(make_pair(1, 1 % mod));
  vector<vector<int> > C = get(1, n, 1, K, 1);
  for (long long idx : need) {
    long long last = f.back().first;
    if (idx < last) continue;
    if (idx - last <= 3) {
      getSimple(idx);
    } else {
      long long start = (last - 1) % n;
      long long need = idx - last - 1;
      vector<vector<int> > now = one;
      long long toEnd = ((n - start < need) ? (n - start) : (need));
      now = now = get((int)(start + 1), start + (int)toEnd, 1, K, 1);
      need -= toEnd;
      vector<vector<int> > now1 = bp(C, need / n);
      now = mul(now, now1);
      toEnd = need % n;
      if (toEnd) {
        now1 = pre[toEnd - 1];
        now = mul(now, now1);
      }
      long long f1 = (f[f.size() - 2].second * 1ll * now[0][0] +
                      f[f.size() - 1].second * 1ll * now[1][0]) %
                     mod;
      long long f2 = (f[f.size() - 2].second * 1ll * now[0][1] +
                      f[f.size() - 1].second * 1ll * now[1][1]) %
                     mod;
      f.push_back(make_pair(idx - 2, f1));
      f.push_back(make_pair(idx - 1, f2));
      getSimple(idx);
    }
  }
  for (int i = (0); i < (f.size()); ++i) {
    if (f[i].first == k) {
      cout << f[i].second << endl;
      break;
    }
  }
  return 0;
}
