#include <bits/stdc++.h>
using namespace std;
const int N = 100010, p = 1000000009;
int n, tot = 0;
struct data1 {
  int x, y;
} w[N];
struct data2 {
  int l, r, m, left, right, d;
} pretree[N * 2];
struct data3 {
  int k1, k2;
};
struct data4 {
  int l, r, left, right;
  data3 s;
} tree[N];
bool compare(data1 a, data1 b) { return (a.x < b.x); }
void prebuild(int d) {
  if (pretree[d].l + 1 == pretree[d].r) {
    pretree[d].d = pretree[d].l;
    return;
  }
  pretree[d].m = (pretree[d].l + pretree[d].r) / 2;
  pretree[d].left = ++tot;
  pretree[tot].l = pretree[d].l;
  pretree[tot].r = pretree[d].m;
  prebuild(tot);
  pretree[d].right = ++tot;
  pretree[tot].l = pretree[d].m;
  pretree[tot].r = pretree[d].r;
  prebuild(tot);
  if (w[pretree[pretree[d].left].d].y > w[pretree[pretree[d].right].d].y)
    pretree[d].d = pretree[pretree[d].left].d;
  else
    pretree[d].d = pretree[pretree[d].right].d;
}
int prequery(int d, int l, int r) {
  if (pretree[d].l == l && pretree[d].r == r)
    return (pretree[d].d);
  else if (r <= pretree[d].m)
    return (prequery(pretree[d].left, l, r));
  else if (l >= pretree[d].m)
    return (prequery(pretree[d].right, l, r));
  else {
    int t1 = prequery(pretree[d].left, l, pretree[d].m);
    int t2 = prequery(pretree[d].right, pretree[d].m, r);
    if (w[t1].y > w[t2].y)
      return (t1);
    else
      return (t2);
  }
}
int max(int a, int b) { return (a > b ? a : b); }
void buildtree(int d, int l, int r) {
  data3 t1, t2;
  tree[d].l = l;
  tree[d].r = r;
  if (l == r) {
    tree[d].s.k1 = tree[d].s.k2 = 0;
    return;
  }
  if (d > l) {
    tree[d].left = prequery(1, l, d);
    buildtree(tree[d].left, l, d - 1);
    t1 = tree[tree[d].left].s;
  } else {
    t1.k1 = 0;
    t1.k2 = -1;
  }
  if (d < r) {
    tree[d].right = prequery(1, d + 1, r + 1);
    buildtree(tree[d].right, d + 1, r);
    t2 = tree[tree[d].right].s;
  } else {
    t2.k1 = 0;
    t2.k2 = -1;
  }
  tree[d].s.k2 = t1.k1 + t2.k1;
  tree[d].s.k1 = max(tree[d].s.k2, 1 + max(t1.k1 + t2.k2, t1.k2 + t2.k1));
}
data3 query(int d, int l, int r) {
  if (l > r) {
    data3 temp;
    temp.k1 = 0;
    temp.k2 = -1;
    return (temp);
  }
  if (tree[d].l == l && tree[d].r == r)
    return (tree[d].s);
  else if (r < d)
    return (query(tree[d].left, l, r));
  else if (l > d)
    return (query(tree[d].right, l, r));
  else {
    data3 t1 = query(tree[d].left, l, d - 1);
    data3 t2 = query(tree[d].right, d + 1, r);
    data3 temp;
    temp.k2 = t1.k1 + t2.k1;
    temp.k1 = max(temp.k2, 1 + max(t1.k1 + t2.k2, t1.k2 + t2.k1));
    return (temp);
  }
}
int getl(int x) {
  if (x > w[n].x)
    return (n + 1);
  else if (x <= w[1].x)
    return (1);
  int l = 1, r = n, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (w[mid].x >= x)
      r = mid;
    else
      l = mid;
  }
  return (r);
}
int getr(int x) {
  if (x < w[1].x) return (0);
  if (x >= w[n].x) return (n);
  int l = 1, r = n, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (w[mid].x <= x)
      l = mid;
    else
      r = mid;
  }
  return (l);
}
int main() {
  int m, k, i, j, l, r, root;
  long long a, b, c, d;
  data3 temp;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= k; i++) scanf("%d %d", &w[i].x, &w[i].y);
  scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d);
  for (i = k + 1; i <= n; i++) {
    w[i].x = (a * w[i - 1].x + b) % p;
    w[i].y = (c * w[i - 1].y + d) % p;
  }
  sort(w + 1, w + n + 1, compare);
  tot = 1;
  pretree[1].l = 1;
  pretree[1].r = n + 1;
  prebuild(1);
  root = prequery(1, 1, n + 1);
  buildtree(root, 1, n);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &l, &r);
    l = getl(l);
    r = getr(r);
    temp = query(root, l, r);
    printf("%d\n", temp.k1);
  }
  return (0);
}
