#include <bits/stdc++.h>
using namespace std;
struct ww {
  int x, y;
} a[100010];
struct w {
  int a0, a1, l, r;
} f[100010];
int i, j, k, n, m, r, x, y;
int L[100010], R[100010], g[100010], zuo[100010], you[100010];
long long A, B, C, D;
inline bool cc1(const ww &a, const ww &b) { return a.x < b.x; }
void dfs(int x) {
  int a = L[x], b = R[x];
  if (a) dfs(a);
  if (b) dfs(b);
  f[x].a0 = f[a].a1 + f[b].a1;
  if (a) f[x].a1 = f[a].a0 + 1 + f[b].a1;
  if (b) f[x].a1 = max(f[x].a1, f[b].a0 + 1 + f[a].a1);
  if (a) f[x].l = f[a].l;
  if (b) f[x].r = f[b].r;
}
w cal(int z) {
  if (!z) return f[z];
  if (x <= f[z].l && f[z].r <= y) return f[z];
  if (f[z].l > y || f[z].r < x) return f[0];
  w A = cal(L[z]), B = cal(R[z]), an = {};
  if (a[z].x > y)
    return A;
  else if (a[z].x < x)
    return B;
  else {
    an.a0 = A.a1 + B.a1;
    if (f[L[z]].r >= x) an.a1 = A.a0 + 1 + B.a1;
    if (f[R[z]].l <= y) an.a1 = max(an.a1, B.a0 + 1 + A.a1);
  }
  return an;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &a[i].x, &a[i].y);
  scanf("%I64d%I64d%I64d%I64d", &A, &B, &C, &D);
  for (i = m + 1; i <= n; i++) {
    a[i].x = (A * a[i - 1].x + B) % 1000000009;
    a[i].y = (C * a[i - 1].y + D) % 1000000009;
  }
  sort(a + 1, a + n + 1, cc1);
  for (i = 1; i <= n; i++) {
    for (; r && a[i].y > a[g[r]].y; r--) L[i] = g[r];
    g[++r] = i;
  }
  r = 0;
  for (i = n; i; i--) {
    for (; r && a[i].y > a[g[r]].y; r--) R[i] = g[r];
    g[++r] = i;
  }
  for (i = 1; i <= n; i++) f[i].l = f[i].r = a[i].x;
  k = 0;
  for (i = 1; i <= n; i++)
    if (a[i].y >= a[k].y) k = i;
  dfs(k);
  scanf("%d", &m);
  f[0].l = 1000000009;
  f[0].r = 0;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    w an = cal(k);
    printf("%d\n", an.a1);
  }
  return 0;
}
