#include <bits/stdc++.h>
using namespace std;
int mod;
inline long long read() {
  char ch = getchar();
  long long nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  long long ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
inline long long min(long long x, long long y, long long z) {
  return min(x, min(y, z));
}
inline long long max(long long x, long long y, long long z) {
  return max(x, max(y, z));
}
inline long long add(long long x, long long y) {
  return x + y >= mod ? x + y - mod : x + y;
}
inline long long add(long long x, long long y, long long z) {
  return add(add(x, y), z);
}
inline long long sub(long long x, long long y) {
  return x - y < 0 ? x - y + mod : x - y;
}
inline long long mul(long long x, long long y) { return 1LL * x * y % mod; }
inline long long mul(long long x, long long y, long long z) {
  return mul(mul(x, y), z);
}
long long n, k;
long long s[50005];
struct Mar {
  long long a[2][2];
  Mar() { memset(a, 0, sizeof(a)); }
};
Mar operator*(Mar x, Mar y) {
  Mar ans;
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      for (long long k = 0; k < 2; k++) {
        ans.a[i][j] = add(ans.a[i][j], mul(x.a[i][k], y.a[k][j]));
      }
    }
  }
  return ans;
}
Mar a[50005], b[50005], ans;
Mar qpow(Mar x, long long y, Mar ans) {
  while (y) {
    if (y & 1) ans = ans * x;
    x = x * x;
    y >>= 1;
  }
  return ans;
}
struct NODE {
  long long x, y, k;
};
NODE q[50005 * 2];
bool cmp(NODE x, NODE y) { return x.x < y.x; }
Mar t[50005 * 4];
void build(long long u, long long l, long long r) {
  if (l == r) {
    t[u] = a[l];
    return;
  }
  long long mid = (l + r) / 2;
  build((u << 1), l, mid), build((u << 1 | 1), mid + 1, r);
  t[u] = t[(u << 1)] * t[(u << 1 | 1)];
}
void update(long long u, long long l, long long r, long long p, Mar x) {
  if (l == r) {
    t[u] = x;
    return;
  }
  long long mid = (l + r) / 2;
  if (p <= mid)
    update((u << 1), l, mid, p, x);
  else
    update((u << 1 | 1), mid + 1, r, p, x);
  t[u] = t[(u << 1)] * t[(u << 1 | 1)];
}
void print(Mar x) {
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) printf("%lld ", x.a[i][j]);
    cout << "\n";
  }
  cout << "\n";
}
signed main() {
  cin >> k >> mod >> n;
  for (long long i = 0; i < n; i++) s[i] = read() % mod;
  for (long long i = 1; i <= n; i++) {
    a[i].a[0][1] = s[i - 1], a[i].a[1][1] = s[i % n], a[i].a[1][0] = 1;
    b[i] = a[i];
    ;
  }
  long long m = read();
  build(1, 1, n);
  for (long long i = 1; i <= m; i++) {
    q[i].x = read(), q[i + m].x = q[i].x + 1;
    q[i].k = 1;
    q[i].y = q[i + m].y = read() % mod;
  }
  m *= 2;
  sort(q + 1, q + m + 1, cmp);
  while (q[m].x > k) m--;
  ans.a[0][1] = 1;
  long long las = 0;
  for (long long i = 1, j = 1; i <= m; j++, i = j) {
    long long id = (q[i].x - 1) / n;
    while (j < m && (q[j + 1].x - 1) / n == id) j++;
    ans = qpow(t[1], id - las, ans);
    las = id;
    for (long long k = i; k <= j; k++) {
      long long _id = (q[k].x - 1) % n + 1;
      b[_id].a[q[k].k][1] = q[k].y;
      update(1, 1, n, _id, b[_id]);
    }
    if (id == k / n) break;
    ans = ans * t[1];
    las++;
    for (long long k = i; k <= j; k++) {
      long long _id = (q[k].x - 1) % n + 1;
      b[_id] = a[_id];
      update(1, 1, n, _id, b[_id]);
    }
  }
  long long id = k / n;
  ans = qpow(t[1], id - las, ans);
  for (long long i = 1; i <= k % n; i++) ans = ans * b[i];
  cout << ans.a[0][0] << endl;
  return 0;
}
