#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 10;
long long mod, k, s[MAXN], n, q;
struct node {
  long long pos, val;
} Ask[MAXN];
struct Matrix {
  long long a[3][3];
  Matrix operator*(const Matrix &x) const {
    Matrix res;
    for (int i = 1; i <= 2; ++i) {
      for (int j = 1; j <= 2; ++j) {
        res.a[i][j] = 0;
      }
    }
    for (int i = 1; i <= 2; ++i) {
      for (int l = 1; l <= 2; ++l) {
        for (int j = 1; j <= 2; ++j) {
          res.a[i][j] = (res.a[i][j] + a[i][l] * x.a[l][j]) % mod;
        }
      }
    }
    return res;
  }
} st[MAXN][20], ans, sum, m;
void read(long long &x) {
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 1) + (x << 3) + s - '0';
    s = getchar();
  }
}
bool cmp(node x, node y) { return x.pos < y.pos; }
Matrix Work(int sta, long long dis) {
  Matrix res;
  res.a[1][1] = 1, res.a[1][2] = 0;
  res.a[2][1] = 0, res.a[2][2] = 1;
  for (int i = 16; i >= 0; --i) {
    if (dis >= (1 << i)) {
      res = res * st[sta][i];
      dis -= (1 << i);
      sta += (1 << i);
    }
  }
  return res;
}
Matrix qpow(Matrix x, long long b) {
  Matrix res;
  res.a[1][1] = 1, res.a[1][2] = 0;
  res.a[2][1] = 0, res.a[2][2] = 1;
  while (b) {
    if (b & 1) {
      res = res * x;
    }
    x = x * x;
    b >>= 1;
  }
  return res;
}
Matrix Solve(long long sta, long long dis) {
  long long x = (n - sta % n + 1) % n;
  Matrix res;
  if (dis >= x) {
    dis -= x;
    int a = sta % n;
    res = Work(a == 0 ? n : a, x);
    res = res * qpow(sum, dis / n);
    dis %= n;
    res = res * Work(1, dis);
  } else {
    int a = sta % n;
    res = Work(a == 0 ? n : a, dis);
  }
  return res;
}
int main() {
  read(k), read(mod), read(n);
  for (int i = 0; i < n; ++i) {
    read(s[i]);
  }
  if (k == 0) {
    printf("0\n");
    return 0;
  }
  ans.a[1][1] = 1, ans.a[1][2] = 0;
  ans.a[2][1] = 0, ans.a[2][2] = 0;
  for (int i = 1; i < n; ++i) {
    st[i][0].a[1][1] = s[i], st[i][0].a[1][2] = 1;
    st[i][0].a[2][1] = s[i - 1], st[i][0].a[2][2] = 0;
  }
  st[n][0].a[1][1] = s[0], st[n][0].a[1][2] = 1;
  st[n][0].a[2][1] = s[n - 1], st[n][0].a[2][2] = 0;
  for (int i = 1; i <= 16; ++i) {
    for (int j = 1; j <= n; ++j) {
      st[j][i] = st[j][i - 1];
      if (j + (1 << (i - 1)) <= n) {
        st[j][i] = st[j][i] * st[j + (1 << (i - 1))][i - 1];
      }
    }
  }
  sum = Work(1, n);
  read(q);
  for (int i = 1; i <= q; ++i) {
    read(Ask[i].pos), read(Ask[i].val);
  }
  Ask[0].pos = -1e18 - 1, Ask[q + 1].pos = 1e18 + 1;
  sort(Ask + 1, Ask + 1 + q, cmp);
  long long Now = 1;
  for (int i = 1; i <= q; ++i) {
    if (k == Ask[i].pos + 1) {
      if (Ask[i - 1].pos + 1 == Ask[i].pos) {
        m.a[1][1] = Ask[i].val, m.a[1][2] = 1;
        m.a[2][1] = Ask[i - 1].val, m.a[2][2] = 0;
        ans = ans * m;
      } else {
        long long dis = Ask[i].pos - Now;
        ans = ans * Solve(Now, dis);
        m.a[1][1] = Ask[i].val, m.a[1][2] = 1;
        m.a[2][1] = s[(k - 2) % n], m.a[2][2] = 0;
        ans = ans * m;
      }
      Now = k;
      break;
    } else if (k > Ask[i].pos + 1) {
      if (Ask[i - 1].pos + 1 == Ask[i].pos) {
        m.a[1][1] = Ask[i].val, m.a[1][2] = 1;
        m.a[2][1] = Ask[i - 1].val, m.a[2][2] = 0;
        ans = ans * m;
        Now = Ask[i].pos + 1;
        if (Ask[i + 1].pos > Ask[i].pos + 1) {
          m.a[1][1] = s[(Ask[i].pos + 1) % n], m.a[1][2] = 1;
          m.a[2][1] = Ask[i].val, m.a[2][2] = 0;
          ans = ans * m;
          Now = Ask[i].pos + 2;
        }
      } else {
        long long dis = Ask[i].pos - Now;
        ans = ans * Solve(Now, dis);
        if (Ask[i].pos > 0) {
          m.a[1][1] = Ask[i].val, m.a[1][2] = 1;
          m.a[2][1] = s[(Ask[i].pos - 1) % n], m.a[2][2] = 0;
          ans = ans * m;
          Now = Ask[i].pos + 1;
        }
        if (Ask[i].pos + 1 < Ask[i + 1].pos) {
          m.a[1][1] = s[(Ask[i].pos + 1) % n], m.a[1][2] = 1;
          m.a[2][1] = Ask[i].val, m.a[2][2] = 0;
          ans = ans * m;
          Now = Ask[i].pos + 2;
        }
      }
    } else {
      break;
    }
  }
  if (Now < k) {
    Matrix res = Solve(Now, k - Now);
    ans = ans * res;
  }
  printf("%lld\n", ans.a[1][1] % mod);
  return 0;
}
