#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
using pii = pair<long long, long long>;
template <class T>
void cmax(T& x, const T& y) {
  if (x < y) x = y;
}
template <class T>
void cmin(T& x, const T& y) {
  if (x > y) x = y;
}
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T>
void unique(vector<T>& v) {
  sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
void reverse(vector<T>& v) {
  reverse(v.begin(), v.end());
}
const long long SZ = 0x191981;
long long k, p, n, m;
const long long maxn = 5e4 + 45;
long long s[maxn];
struct mat {
  long long a[2][2];
  ~mat() { clear(); }
  void clear() { memset(a, 0, sizeof(a)); }
  long long* operator[](long long x) { return a[x]; }
};
mat b[maxn];
mat operator*(mat a, mat b) {
  mat c;
  for (long long i = 0; i <= 1; i++)
    for (long long j = 0; j <= 1; j++) c[i][j] = 0;
  for (long long i = 0; i <= 1; i++)
    for (long long j = 0; j <= 1; j++)
      for (long long k = 0; k <= 1; k++)
        c[i][j] = (c[i][j] + a[i][k] * b[k][j] % p) % p;
  return c;
}
mat operator*=(mat& a, mat b) { return a = a * b; }
mat qpow(mat f, mat bs, long long y) {
  for (; y; y >>= 1, bs *= bs)
    if (y & 1) f *= bs;
  return f;
}
mat a[maxn];
mat sum[maxn << 2];
mat ans;
void build(long long l, long long r, long long rt) {
  if (l == r) {
    sum[rt][0][0] = 0, sum[rt][0][1] = s[l - 1];
    sum[rt][1][0] = 1, sum[rt][1][1] = s[l % n];
    b[l] = a[l] = sum[rt];
    return;
  }
  long long mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  sum[rt] = sum[rt << 1] * sum[rt << 1 | 1];
}
void change(long long l, long long r, long long rt, long long x, mat v) {
  if (l == r) return sum[rt] = v, void();
  long long mid = (l + r) >> 1;
  if (x <= mid)
    change(l, mid, rt << 1, x, v);
  else
    change(mid + 1, r, rt << 1 | 1, x, v);
  sum[rt] = sum[rt << 1] * sum[rt << 1 | 1];
}
struct que {
  long long x, y, k;
} q[maxn << 1];
signed main() {
  cin >> k >> p >> n;
  for (long long i = 0; i < n; i++) cin >> s[i];
  build(1, n, 1);
  cin >> m;
  for (long long i = 1; i <= m; i++) cin >> q[i].x >> q[i].y;
  for (long long i = 1; i <= m; i++) {
    q[i].y %= p;
    q[i].k = 1;
    q[i + m] = q[i];
    q[i + m].x++;
    q[i + m].k--;
  }
  m <<= 1;
  sort(q + 1, q + m + 1, [](const que& x, const que& y) { return x.x < y.x; });
  while (m > 0 && q[m].x > k) --m;
  ans.clear();
  ans[0][1] = 1;
  long long lasbl = 0;
  for (long long i = 1, j = 1; i <= m; i = ++j) {
    long long bl = (q[i].x - 1) / n;
    while (j < m && bl == (q[j + 1].x - 1) / n) ++j;
    ans = qpow(ans, sum[1], bl - lasbl);
    lasbl = bl;
    for (long long qwq = i; qwq <= j; qwq++) {
      long long d = (q[qwq].x - 1) % n + 1;
      b[d][q[qwq].k][1] = q[qwq].y;
      change(1, n, 1, d, b[d]);
    }
    if (bl == k / n) break;
    ans = ans * sum[1];
    lasbl = bl + 1;
    for (long long qwq = i; qwq <= j; qwq++) {
      long long d = (q[qwq].x - 1) % n + 1;
      b[d] = a[d];
      change(1, n, 1, d, b[d]);
    }
  }
  long long bl = k / n;
  ans = qpow(ans, sum[1], bl - lasbl);
  for (long long i = 1; i <= k % n; i++) ans *= b[i];
  cout << ans[0][0] << '\n';
  return 0;
}
