#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000;
vector<long long> s;
vector<pair<long long, long long> > bad;
long long n;
long long m;
long long k;
struct matr {
  long long a;
  long long b;
  long long c;
  long long d;
  matr() {
    a = 1;
    b = 0;
    c = 0;
    d = 1;
  }
  matr(long long s1, long long s2) {
    a = 0;
    b = s1 % mod;
    c = 1;
    d = s2 % mod;
  }
  void print() {
    cout << "[" << a << " " << b << "\n " << c << " " << d << "]" << endl;
  }
};
vector<matr> go_matr;
matr per;
time_t time_pow = 0;
matr mul(matr f, matr s) {
  matr res;
  res.a = f.a * s.a + f.b * s.c;
  res.b = f.a * s.b + f.b * s.d;
  res.c = f.c * s.a + f.d * s.c;
  res.d = f.c * s.b + f.d * s.d;
  res.a %= mod;
  res.b %= mod;
  res.c %= mod;
  res.d %= mod;
  return res;
}
matr power(matr f, long long st) {
  if (st == 0) return matr();
  if (st == 1) return f;
  matr res = power(f, st / 2);
  res = mul(res, res);
  if (st % 2 == 1) {
    res = mul(res, f);
  }
  return res;
}
class matr_segm_tree_t {
  long long n;
  vector<matr> tree_n;
  void assign(long long v, long long tl, long long tr, vector<matr>& a) {
    if (tl == tr) {
      tree_n[v] = a[tl];
      return;
    }
    long long tm = (tl + tr) / 2;
    assign(2 * v + 1, tl, tm, a);
    assign(2 * v + 2, tm + 1, tr, a);
    tree_n[v] = mul(tree_n[2 * v + 1], tree_n[2 * v + 2]);
  }
  matr get(long long v, long long tl, long long tr, long long l, long long r) {
    if (l > r) return matr();
    if (tl == l && tr == r) return tree_n[v];
    long long tm = (tl + tr) / 2;
    return mul(get(2 * v + 1, tl, tm, l, min(r, tm)),
               get(2 * v + 2, tm + 1, tr, max(l, tm + 1), r));
  }

 public:
  void init(vector<matr>& a) {
    n = a.size();
    tree_n.resize(n * 4);
    assign(0, 0, n - 1, a);
  }
  matr get(long long l, long long r) {
    time_t stdd = clock();
    matr res = get(0, 0, n - 1, l, r);
    time_pow += clock() - stdd;
    return res;
  }
} seq;
void precalc() {
  go_matr.resize(n);
  for (long long i = 0; i < n - 1; ++i) go_matr[i] = matr(s[i], s[i + 1]);
  go_matr[n - 1] = matr(s[n - 1], s[0]);
  seq.init(go_matr);
  per = seq.get(0, n - 1);
}
matr line(long long from, long long to) {
  if (from > to) return matr();
  long long per_from;
  long long per_to;
  long long pos_from;
  long long pos_to;
  per_from = from / n;
  per_to = to / n;
  pos_from = from % n;
  pos_to = to % n;
  matr res;
  if (per_from == per_to) {
    res = seq.get(pos_from, pos_to);
  } else {
    long long l = per_to - per_from - 1;
    matr left = seq.get(pos_from, n - 1);
    matr mid = power(per, l);
    matr right = seq.get(0, pos_to);
    res = mul(left, mul(mid, right));
  }
  return res;
}
map<long long, long long> ss;
vector<long long> bad_matr_pos;
long long get_s(long long idx) {
  if (ss.count(idx)) return ss[idx];
  return s[(idx + n) % n];
}
long long solve() {
  if (k == 0) {
    return 0;
  }
  if (k == 1) {
    return 1 % mod;
  }
  long long pos = 0;
  matr res;
  long long xx = 0;
  --k;
  while (true) {
    if (xx < bad_matr_pos.size() && (bad_matr_pos[xx] - 1) < k - 1) {
      long long next_pos = bad_matr_pos[xx] - 1;
      res = mul(res, line(pos, next_pos));
      res =
          mul(res, matr(get_s(bad_matr_pos[xx]), get_s(bad_matr_pos[xx] + 1)));
      pos = bad_matr_pos[xx] + 1;
      ++xx;
    } else {
      long long next_pos = k - 1;
      res = mul(res, line(pos, next_pos));
      return res.d % mod;
    }
  }
}
void input() {
  scanf("%I64d %d", &k, &mod);
  scanf("%d", &n);
  s.resize(n);
  for (long long i = 0; i < n; ++i) scanf("%d", &s[i]);
  scanf("%d", &m);
  bad.resize(m);
  ss.clear();
  bad_matr_pos.clear();
  for (long long i = 0; i < m; ++i) {
    scanf("%I64d %d", &bad[i].first, &bad[i].second);
    ss[bad[i].first] = bad[i].second;
    bad_matr_pos.push_back(bad[i].first - 1);
    bad_matr_pos.push_back(bad[i].first);
  }
  sort(bad_matr_pos.begin(), bad_matr_pos.end());
  bad_matr_pos.resize(unique(bad_matr_pos.begin(), bad_matr_pos.end()) -
                      bad_matr_pos.begin());
  precalc();
}
long long ans;
void rnd_test() {
  cout << "\nTest: \n";
  s.resize(n);
  k = rand() % 20;
  mod = 1 + rand() % 20;
  n = 2 + rand() % 9;
  m = 2 + rand() % 9;
  s.resize(n);
  cout << k << " " << mod << endl;
  cout << n << endl;
  for (long long i = 0; i < n; ++i) {
    s[i] = rand() % 20;
    cout << s[i] << " ";
  }
  cout << endl;
  bad.resize(m);
  ss.clear();
  bad_matr_pos.clear();
  cout << m << endl;
  for (long long i = 0; i < m; ++i) {
    long long j = rand() % 100 + n;
    long long k = rand() % 100;
    cout << j << " " << k << endl;
    ss[j] = k;
    bad_matr_pos.push_back(j - 1);
    bad_matr_pos.push_back(j);
  }
  sort(bad_matr_pos.begin(), bad_matr_pos.end());
  bad_matr_pos.resize(unique(bad_matr_pos.begin(), bad_matr_pos.end()) -
                      bad_matr_pos.begin());
  precalc();
  vector<long long> ff(2);
  ff[0] = 0;
  ff[1] = 1 % mod;
  for (long long i = 2; i <= k; ++i) {
    ff.push_back(get_s(i - 2) * ff[i - 2] + get_s(i - 1) * ff[i - 1]);
    ff.back() %= mod;
  }
  ans = ff[k];
}
int main() {
  time_t t1 = clock();
  input();
  cout << solve() << endl;
  time_t t2 = clock();
}
