#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 5e4 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = a * a % M) ret = 1ll * ret * a % M;
  return ret;
}
long long k, p;
struct node {
  long long A[2][2];
  node(long long a = 1, long long b = 0, long long c = 0, long long d = 1) {
    A[0][0] = a;
    A[0][1] = b;
    A[1][0] = c;
    A[1][1] = d;
  }
};
node operator*(node a, node b) {
  long long i, j, k;
  node ret;
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++)
      ret.A[i][j] = (a.A[i][0] * b.A[0][j] % p + a.A[i][1] * b.A[1][j] % p) % p;
  return ret;
}
node POW(node a, long long num) {
  node ret;
  while (num) {
    if (num & 1) ret = ret * a;
    a = a * a;
    num /= 2;
  }
  return ret;
}
long long n, m;
long long i, j;
long long s[maxn];
node sum[maxn << 2], a[maxn];
void build(long long x, long long l, long long r) {
  if (l == r) {
    sum[x] = a[l];
    return;
  }
  long long mid = (l + r) / 2;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  sum[x] = sum[x << 1] * sum[x << 1 | 1];
}
node query(long long x, long long l, long long r, long long L, long long R) {
  if (l <= L && R <= r) return sum[x];
  node ret;
  long long mid = (L + R) / 2;
  if (mid >= l) ret = ret * query(x << 1, l, r, L, mid);
  if (r > mid) ret = ret * query(x << 1 | 1, l, r, mid + 1, R);
  return ret;
}
node ans, all;
void moveto(long long now, long long should, node &ans) {
  if (now == should) return;
  if (now / n == (should - 1) / n) {
    ans = ans * query(1, now % n + 1, (should - 1) % n + 1, 1, n);
    now = should;
  } else {
    ans = ans * query(1, now % n + 1, n, 1, n);
    now = now / n * n + n;
    ans = ans * POW(all, (should - 1) / n - now / n);
    now = (should - 1) / n * n;
    ans = ans * query(1, 1, (should - 1) % n + 1, 1, n);
  }
}
pair<long long, long long> b[maxn];
int main() {
  scanf("%I64d%I64d", &k, &p);
  scanf("%I64d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &s[i]);
  s[n + 1] = s[1];
  for (i = 1; i <= n; i++) a[i] = node(0, s[i] % p, 1, s[i + 1] % p);
  for (i = 1; i <= n; i++) all = all * a[i];
  scanf("%I64d", &m);
  build(1, 1, n);
  for (i = 0; i < m; i++) scanf("%I64d%I64d", &b[i].first, &b[i].second);
  sort(b, b + m);
  long long now = 0;
  i = 0;
  ans = node(0, 1, 0, 0);
  for (i = 0; i < m; i++) {
    if (b[i].first > k) break;
    if (now != b[i].first) {
      moveto(now, b[i].first - 1, ans);
      now = b[i].first - 1;
      ans = ans * node(0, s[(b[i].first - 1) % n + 1] % p, 1, b[i].second % p);
      now++;
    }
    if (now == k) break;
    if (b[i + 1].first == b[i].first + 1)
      ans = ans * node(0, b[i].second % p, 1, b[i + 1].second % p);
    else
      ans = ans * node(0, b[i].second % p, 1, s[(b[i].first + 1) % n + 1] % p);
    now++;
  }
  moveto(now, k, ans);
  printf("%I64d\n", ans.A[0][0]);
}
