#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
const int N = 233333, mo = 1e9 + 9;
int n, k, x[N], y[N], fa[N], rt, f[N][2], mn[N], mx[N], lc[N], rc[N];
vector<int> e[N];
struct dot {
  int x, y;
} s[N];
bool cmp(dot a, dot b) { return a.x < b.x; }
inline void gettree() {
  static int sta[N];
  int top = 0;
  sta[++top] = 1;
  for (register int i = (2); i <= (n); i++) {
    int x = 0;
    while (top && s[sta[top]].y < s[i].y) x = sta[top--];
    if (top) fa[i] = sta[top];
    sta[++top] = i;
    if (x) fa[x] = i;
  }
  for (register int i = (1); i <= (n); i++) {
    e[fa[i]].push_back(i);
    if (i < fa[i])
      lc[fa[i]] = i;
    else
      rc[fa[i]] = i;
  }
}
inline void DFS(int u) {
  int m = -1e9;
  f[u][1] = 1;
  mn[u] = u;
  mx[u] = u;
  for (register int i = (((int)e[u].size()) - 1); i >= (0); i--) {
    int v = e[u][i];
    DFS(e[u][i]);
    f[u][0] += max(f[v][1], f[v][0]);
    f[u][1] += max(f[v][1], f[v][0]);
    m = max(m, f[v][0] - max(f[v][1], f[v][0]));
    mn[u] = min(mn[u], mn[v]);
    mx[u] = max(mx[u], mx[v]);
  }
  f[u][1] += m;
}
inline pair<int, int> solve(int k, int l, int r) {
  if (!k || l > r) return pair<int, int>(-1e9, 0);
  if (l <= mn[k] && r >= mx[k]) return pair<int, int>(f[k][0], f[k][1]);
  if (r < k) {
    pair<int, int> t = solve(lc[k], l, r);
    return t;
  }
  if (l > k) {
    pair<int, int> t = solve(rc[k], l, r);
    return t;
  }
  pair<int, int> res = pair<int, int>(0, 1);
  pair<int, int> a = solve(lc[k], l, k - 1), b = solve(rc[k], k + 1, r);
  res.first = max(max(a.second, a.first), 0) + max(max(b.second, b.first), 0);
  res.second = 1 + max(a.first + max(max(b.second, b.first), 0),
                       max(max(a.second, a.first), 0) + b.first);
  return res;
}
int main() {
  read(n);
  read(k);
  for (register int i = (1); i <= (k); i++) read(x[i]), read(y[i]);
  int a, b, c, d;
  read(a);
  read(b);
  read(c);
  read(d);
  for (register int i = (k + 1); i <= (n); i++)
    x[i] = (1LL * a * x[i - 1] + b) % mo, y[i] = (1LL * c * y[i - 1] + d) % mo;
  for (register int i = (1); i <= (n); i++) s[i].x = x[i], s[i].y = y[i];
  sort(s + 1, s + n + 1, cmp);
  gettree();
  for (register int i = (1); i <= (n); i++) x[i] = s[i].x, y[i] = s[i].y;
  for (register int i = (1); i <= (n); i++)
    if (!fa[i]) rt = i;
  DFS(rt);
  int q;
  read(q);
  while (q--) {
    int l, r;
    read(l);
    read(r);
    l = lower_bound(x + 1, x + n + 1, l) - x;
    r = upper_bound(x + 1, x + n + 1, r) - x - 1;
    pair<int, int> tmp = solve(rt, l, r);
    printf("%d\n", max(max(tmp.first, tmp.second), 0));
  }
  return 0;
}
