#include <bits/stdc++.h>
using namespace std;
inline int Read() {
  char c = getchar();
  int num = 0;
  while ('0' > c || c > '9') c = getchar();
  while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
  return (num);
}
pair<int, int> f[200010];
struct Poi {
  int x, y;
} p[200010];
int ch[200010][2], mn[200010], mx[200010], n, m;
inline pair<int, int> Meg(pair<int, int> a, pair<int, int> b) {
  if (a.second == -1 && b.second == -1) return (make_pair(0, 0));
  if (a.second == -1) swap(a, b);
  if (b.second == -1) return (make_pair(max(a.first, a.second), 1 + a.first));
  int nm = max(a.first + b.second, a.second + b.first) + 1;
  nm = max(a.second + b.second, nm), nm = max(a.first + b.first + 1, nm);
  return (make_pair(max(a.first, a.second) + max(b.first, b.second), nm));
}
inline int Dfs(int l, int r) {
  int hg = l;
  for (int i = l + 1; i <= r; i++)
    if (p[i].y > p[hg].y) hg = i;
  mn[hg] = mx[hg] = p[hg].x;
  if (l < hg)
    ch[hg][0] = Dfs(l, hg - 1), mn[hg] = min(mn[hg], mn[ch[hg][0]]),
    mx[hg] = max(mx[hg], mx[ch[hg][0]]);
  if (hg < r)
    ch[hg][1] = Dfs(hg + 1, r), mn[hg] = min(mn[hg], mn[ch[hg][1]]),
    mx[hg] = max(mx[hg], mx[ch[hg][1]]);
  f[hg] = Meg(f[ch[hg][0]], f[ch[hg][1]]);
  return (hg);
}
inline pair<int, int> Ask(int x, int l, int r) {
  if (l <= mn[x] && mx[x] <= r) return (f[x]);
  if (!x || l > mx[x] || r < mn[x]) return (f[0]);
  if (r < p[x].x) return (Ask(ch[x][0], l, r));
  if (p[x].x < l) return (Ask(ch[x][1], l, r));
  return (Meg(Ask(ch[x][0], l, r), Ask(ch[x][1], l, r)));
}
bool Cmpx(Poi x, Poi y) { return (x.x < y.x); }
int main() {
  n = Read(), m = Read();
  for (int i = 1; i <= m; i++) p[i].x = Read(), p[i].y = Read();
  int a = Read(), b = Read(), c = Read(), d = Read();
  for (int i = m + 1; i <= n; i++) {
    p[i].x = (p[i - 1].x * 1ll * a + b) % 1000000009;
    p[i].y = (p[i - 1].y * 1ll * c + d) % 1000000009;
  }
  sort(p + 1, p + 1 + n, Cmpx);
  f[0].second = -1;
  int rt = Dfs(1, n);
  m = Read();
  for (int i = 1; i <= m; i++) {
    int l = Read(), r = Read();
    pair<int, int> as = Ask(rt, l, r);
    printf("%d\n", max(as.first, as.second));
  }
}
