#include <bits/stdc++.h>
using namespace std;
const int N = 100005, MOD = 1e9 + 9;
int n, k;
int x[N], y[N];
int A, B, C, D;
int srt[N];
int L[N], R[N], DP[N][2];
bool cmp(int i, int j) { return y[i] > y[j]; }
int tmpa[N], tmpb[N];
int go(int l, int r) {
  if (l > r) return -1;
  int root = srt[l];
  if (l == r) {
    L[root] = R[root] = -1;
    DP[root][0] = DP[root][1] = 0;
    return root;
  }
  int s = 0, t = 0;
  for (int i = l + 1; i <= r; i++)
    if (x[srt[i]] < x[root])
      tmpa[s++] = srt[i];
    else
      tmpb[t++] = srt[i];
  for (int i = l; i < l + s; i++) srt[i] = tmpa[i - l];
  srt[l + s] = root;
  for (int i = l + s + 1; i <= r; i++) srt[i] = tmpb[i - l - s - 1];
  int lc = go(l, l + s - 1);
  int rc = go(l + s + 1, r);
  L[root] = lc;
  R[root] = rc;
  DP[root][0] = (lc >= 0 ? DP[lc][1] : 0) + (rc >= 0 ? DP[rc][1] : 0);
  DP[root][1] = max((lc >= 0 ? 1 + DP[lc][0] : 0) + (rc >= 0 ? DP[rc][1] : 0),
                    (lc >= 0 ? DP[lc][1] : 0) + (rc >= 0 ? 1 + DP[rc][0] : 0));
  DP[root][1] = max(DP[root][1], DP[root][0]);
  return root;
}
int tbl[N][2];
void ask(int r, int ll, int rr, int ql, int qr) {
  if (r == -1) return;
  if (ll >= ql && rr <= qr) {
    tbl[r][0] = DP[r][0];
    tbl[r][1] = DP[r][1];
    return;
  }
  if (x[r] < ql) {
    ask(R[r], x[r] + 1, rr, ql, qr);
    if (R[r] >= 0) {
      tbl[r][0] = tbl[R[r]][0];
      tbl[r][1] = tbl[R[r]][1];
    } else
      tbl[r][0] = -1, tbl[r][1] = 0;
    return;
  }
  if (x[r] > qr) {
    ask(L[r], ll, x[r] - 1, ql, qr);
    if (L[r] >= 0) {
      tbl[r][0] = tbl[L[r]][0];
      tbl[r][1] = tbl[L[r]][1];
    } else
      tbl[r][0] = -1, tbl[r][1] = 0;
    return;
  }
  int LY = -1, LN = 0, RY = -1, RN = 0;
  if (L[r] >= 0) {
    ask(L[r], ll, x[r] - 1, ql, qr);
    LY = tbl[L[r]][0];
    LN = tbl[L[r]][1];
  }
  if (R[r] >= 0) {
    ask(R[r], x[r] + 1, rr, ql, qr);
    RY = tbl[R[r]][0];
    RN = tbl[R[r]][1];
  }
  tbl[r][0] = max(LY, LN) + max(RY, RN);
  tbl[r][1] = max(LY + 1 + RN, RY + 1 + LN);
  tbl[r][1] = max(tbl[r][1], tbl[r][0]);
}
int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) scanf("%d%d", &x[i], &y[i]);
  scanf("%d%d%d%d", &A, &B, &C, &D);
  for (int i = k + 1; i <= n; i++) {
    x[i] = (A * 1LL * x[i - 1] + B) % MOD;
    y[i] = (C * 1LL * y[i - 1] + D) % MOD;
  }
  for (int i = 1; i <= n; i++) srt[i] = i;
  sort(srt + 1, srt + 1 + n, cmp);
  int root = srt[1];
  go(1, n);
  int m;
  scanf("%d", &m);
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    ask(root, 0, MOD - 1, l, r);
    int ans = tbl[root][1];
    printf("%d\n", ans);
  }
  return 0;
}
