#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
inline void read(int &x) {
  char ch = getchar();
  int f = 1;
  x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
int n, m, k, rt, size[100050], dp[100050][2], ch[100050][2];
struct node {
  int x, y;
  bool operator<(const node &a) const {
    if (x == a.x) return y < a.y;
    return x < a.x;
  }
} p[100050];
void gen() {
  int a, b, c, d;
  read(a), read(b), read(c), read(d);
  for (register int i = k + 1; i <= n; ++i)
    p[i].x = (1ll * a * p[i - 1].x + b) % 1000000009,
    p[i].y = (1ll * c * p[i - 1].y + d) % 1000000009;
}
int mx(int u) { return max(dp[u][0], dp[u][1]); }
void update(int u) {
  size[u] = size[ch[u][0]] + size[ch[u][1]] + 1;
  if (!ch[u][0] && !ch[u][1])
    dp[u][0] = dp[u][1] = 0;
  else if (!ch[u][0] || !ch[u][1]) {
    int t = ch[u][0] + ch[u][1];
    dp[u][0] = mx(t), dp[u][1] = dp[t][0] + 1;
  } else {
    dp[u][0] = mx(ch[u][0]) + mx(ch[u][1]);
    dp[u][1] =
        max(dp[ch[u][0]][0] + mx(ch[u][1]), mx(ch[u][0]) + dp[ch[u][1]][0]) + 1;
  }
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  int u;
  if (p[x].y > p[y].y)
    u = x, ch[x][1] = merge(ch[x][1], y);
  else
    u = y, ch[y][0] = merge(x, ch[y][0]);
  update(u);
  return u;
}
void split(int u, int k, int &x, int &y) {
  if (!u)
    x = y = 0;
  else {
    if (k <= size[ch[u][0]])
      y = u, split(ch[u][0], k, x, ch[u][0]);
    else
      x = u, split(ch[u][1], k - size[ch[u][0]] - 1, ch[u][1], y);
    update(u);
  }
}
int main() {
  read(n), read(k);
  for (register int i = 1; i <= k; ++i) read(p[i].x), read(p[i].y);
  gen();
  sort(p + 1, p + n + 1);
  for (register int i = 1; i <= n; ++i) size[i] = 1, rt = merge(rt, i);
  read(m);
  int x, y, z, l, r;
  while (m--) {
    read(l), read(r);
    l = lower_bound(p + 1, p + n + 1, node{l, -1}) - p,
    r = lower_bound(p + 1, p + n + 1, node{r + 1, -1}) - p - 1;
    split(rt, r, y, z), split(y, l - 1, x, y);
    cout << max(dp[y][0], dp[y][1]) << endl;
    rt = merge(merge(x, y), z);
  }
  return 0;
}
