#include <bits/stdc++.h>
using namespace std;
const long long infl = ~0LLU >> 2;
template <class T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <class T>
inline void Max(T &x, T y) {
  if (y > x) x = y;
}
int mod;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
inline int Mul(int x, int y) { return (int)((long long)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) { return Pow(x, mod - 2); }
const int maxn = 50000;
struct Mat {
  int a, b, c, d;
  Mat operator*(const Mat &r) const {
    int A = Add(Mul(a, r.a) + Mul(b, r.c));
    int B = Add(Mul(b, r.d) + Mul(a, r.b));
    int C = Add(Mul(c, r.a) + Mul(d, r.c));
    int D = Add(Mul(d, r.d) + Mul(c, r.b));
    return (Mat){A, B, C, D};
  }
};
Mat MakeMat(int x, int y) { return (Mat){y, 1, x, 0}; }
Mat Pow(Mat a, long long b) {
  Mat c = (Mat){1, 0, 0, 1};
  for (; b; b >>= 1) {
    if (b & 1) c = c * a;
    a = a * a;
  }
  return c;
}
int n, m;
long long K;
int s[maxn];
pair<long long, int> change[maxn + 1];
Mat T[maxn << 1], all, val;
long long now;
int QueryS(long long j) {
  int i = lower_bound(change, change + m, make_pair(j, -1)) - change;
  if (i == m || change[i].first != j) return s[j % n];
  return change[i].second;
}
void Init(void) {
  for (int i = 0; i < n; ++i) {
    int x = s[(i - 2 + n) % n];
    int y = s[(i - 1 + n) % n];
    T[n + i] = MakeMat(x, y);
  }
  for (int i = n - 1; i >= 1; --i) {
    T[i] = T[i << 1] * T[i << 1 | 1];
  }
  all = (Mat){1, 0, 0, 1};
  for (int i = 0; i < n; ++i) {
    all = all * T[n + i];
  }
}
Mat Query(int l, int r) {
  Mat L = (Mat){1, 0, 0, 1}, R = L;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) L = L * T[l++];
    if (r & 1) R = T[--r] * R;
  }
  return L * R;
}
void Goto(long long x) {
  long long L = now + 1, R = x + 1;
  long long M1 = (L + n - 1) / n * n;
  long long M2 = R / n * n;
  if (M1 <= M2) {
    val = val * Query((L - 1) % n + 1, n);
    val = val * Pow(all, (M2 - M1) / n);
    val = val * Query(0, R % n);
    now = x;
  } else {
    val = val * Query(L % n, R % n);
    now = x;
  }
}
void BruteGoto(long long x) {
  while (now < x) {
    ++now;
    int s1 = QueryS(now - 2);
    int s2 = QueryS(now - 1);
    val = val * MakeMat(s1, s2);
  }
}
int main(void) {
  scanf("%lld%d%d", &K, &mod, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", s + i);
    s[i] %= mod;
  }
  Init();
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    long long j;
    int v;
    scanf("%lld%d", &j, &v);
    change[i] = {j, v};
  }
  sort(change, change + m);
  val = (Mat){1, 0, 0, 0};
  now = 1;
  if (mod == 1 || K == 0) {
    puts("0");
    return 0;
  } else if (K == 1) {
    puts("1");
    return 0;
  }
  int nxt = 0;
  while (now < K) {
    long long stop = nxt == m ? K + 1000 : change[nxt].first;
    if (stop < K) {
      if (stop > now) Goto(stop);
      BruteGoto(min(K, stop + 2));
      ++nxt;
    } else {
      if (K > now) Goto(K);
    }
  }
  printf("%d\n", val.a);
  return 0;
}
