#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
};
struct point a[100010];
struct unit {
  int s0, s1, num, l, r, ls, rs, n0, n1;
};
struct unit f[100010];
int n, k, m, x, y, root, sa, sb, sc, sd, mod = 1000000009;
bool cmp(point p1, point p2) { return p1.x < p2.x; }
void build(int &i, int l, int r) {
  int j, k = l;
  if (l > r) return;
  for (j = l + 1; j <= r; j++)
    if (a[j].y > a[k].y) k = j;
  i = k;
  f[i].l = f[i].r = a[k].x;
  if (l == r) return;
  build(f[i].ls, l, k - 1);
  build(f[i].rs, k + 1, r);
  if (f[i].ls) f[i].l = f[f[i].ls].l;
  if (f[i].rs) f[i].r = f[f[i].rs].r;
  f[i].s1 = 0;
  if (f[i].ls)
    f[i].s1 =
        max(f[i].s1, f[f[i].ls].s0 + max(f[f[i].rs].s0, f[f[i].rs].s1) + 1);
  if (f[i].rs)
    f[i].s1 =
        max(f[i].s1, f[f[i].rs].s0 + max(f[f[i].ls].s0, f[f[i].ls].s1) + 1);
  f[i].s0 =
      max(f[f[i].ls].s0, f[f[i].ls].s1) + max(f[f[i].rs].s0, f[f[i].rs].s1);
}
void query(int i) {
  f[i].n0 = f[i].n1 = f[f[i].ls].n0 = f[f[i].ls].n1 = f[f[i].rs].n0 =
      f[f[i].rs].n1 = 0;
  if (f[i].l > y || f[i].r < x) return;
  if (f[i].l >= x && f[i].r <= y) {
    f[i].n0 = f[i].s0;
    f[i].n1 = f[i].s1;
    return;
  }
  if (a[i].x >= x && a[i].x <= y) {
    query(f[i].ls);
    query(f[i].rs);
    if (f[i].ls && f[f[i].ls].r >= x) {
      f[i].n1 = max(f[i].n1, f[f[i].ls].n0 +
                                 ((f[i].rs && f[f[i].rs].l <= y)
                                      ? max(f[f[i].rs].n0, f[f[i].rs].n1)
                                      : 0) +
                                 1);
      f[i].n0 += max(f[f[i].ls].n0, f[f[i].ls].n1);
    }
    if (f[i].rs && f[f[i].rs].l <= y) {
      f[i].n1 = max(f[i].n1, f[f[i].rs].n0 +
                                 ((f[i].ls && f[f[i].ls].r >= x)
                                      ? max(f[f[i].ls].n0, f[f[i].ls].n1)
                                      : 0) +
                                 1);
      f[i].n0 += max(f[f[i].rs].n0, f[f[i].rs].n1);
    }
  } else if (a[i].x < x) {
    query(f[i].rs);
    f[i].n0 = f[f[i].rs].n0;
    f[i].n1 = f[f[i].rs].n1;
  } else {
    query(f[i].ls);
    f[i].n0 = f[f[i].ls].n0;
    f[i].n1 = f[f[i].ls].n1;
  }
}
int main() {
  int i, j;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; i++) scanf("%d%d", &a[i].x, &a[i].y);
  scanf("%d%d%d%d", &sa, &sb, &sc, &sd);
  for (i = k + 1; i <= n; i++) {
    a[i].x = ((long long)a[i - 1].x * sa + sb) % mod;
    a[i].y = ((long long)a[i - 1].y * sc + sd) % mod;
  }
  sort(a + 1, a + n + 1, cmp);
  build(root, 1, n);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    query(root);
    printf("%d\n", max(f[root].n0, f[root].n1));
  }
  return 0;
}
