#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct matrix {
  long long x[2][2];
  matrix() { memset(x, 0, sizeof(x)); }
};
const int maxn = 50010;
const int maxe = 16;
long long k, p;
int n;
int s[maxn];
int m;
map<long long, long long> except;
vector<long long> v;
matrix sp[maxn][maxe];
matrix mul(matrix A, matrix B) {
  matrix res;
  for (int i = (0); i < (2); i++)
    for (int j = (0); j < (2); j++)
      for (int k = (0); k < (2); k++)
        res.x[i][j] = (res.x[i][j] + A.x[i][k] * B.x[k][j]) % p;
  return res;
}
matrix ex(matrix A, long long k) {
  if (k == 1) return A;
  if (k & 1) return mul(A, ex(A, k - 1));
  matrix T = ex(A, k >> 1);
  return mul(T, T);
}
matrix cal(int i, long long d) {
  matrix res;
  res.x[0][0] = res.x[1][1] = 1;
  if (d == 0) return res;
  if (d > n) {
    long long k = d / n;
    d %= n;
    return mul(ex(cal(i, n), k), cal(i, d));
  }
  for (int j = (maxe)-1; j >= (0); j--)
    if (d >= 1 << j)
      return mul(sp[i][j], cal((i + (1 << j)) % n, d - (1 << j)));
}
void solve() {
  scanf("%I64d%I64d", &k, &p);
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d", s + i);
  for (int i = (0); i < (n); i++) {
    sp[i][0].x[0][0] = s[(i + 1) % n];
    sp[i][0].x[0][1] = 1;
    sp[i][0].x[1][0] = s[i];
  }
  for (int j = (0); j < (maxe - 1); j++)
    for (int i = (0); i < (n); i++)
      sp[i][j + 1] = mul(sp[i][j], sp[(i + (1 << j)) % n][j]);
  scanf("%d", &m);
  for (int i = (0); i < (m); i++) {
    long long j, v;
    scanf("%I64d%I64d", &j, &v);
    except[j] = v;
  }
  if (k == 0) {
    printf("0");
    return;
  }
  for (map<long long, long long>::iterator it = except.begin();
       it != except.end(); it++) {
    long long u = it->first;
    if (u >= k) continue;
    if (u <= k - 2) v.push_back(u);
    if (u > 0) v.push_back(u - 1);
  }
  v.push_back(0);
  v.push_back(k - 2);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  matrix res;
  res.x[0][0] = 1;
  res.x[0][1] = 0;
  res = mul(res, sp[0][0]);
  for (int i = (0); i < (int((v).size()) - 1); i++) {
    long long x = v[i] + 1;
    long long y = v[i + 1] - 1;
    long long d = y - x + 1;
    if (d > 0) res = mul(res, cal(x % n, d));
    matrix tmp;
    if (except.count(y + 2))
      tmp.x[0][0] = except[y + 2];
    else
      tmp.x[0][0] = s[(y + 2) % n];
    if (except.count(y + 1))
      tmp.x[1][0] = except[y + 1];
    else
      tmp.x[1][0] = s[(y + 1) % n];
    tmp.x[0][1] = 1;
    res = mul(res, tmp);
  }
  cout << res.x[0][0] % p;
}
int main() {
  solve();
  return 0;
}
