#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009, n = 100005;
int N, K, M, i, A, B, C, D, u, v, l, r;
int fa[n], L[n], R[n], Lp[n], Rp[n], S[n], f[n];
struct node {
  int X, Y, H;
} P[n];
struct tree {
  int g1, g2;
} G[n], res;
void read(int &x) {
  char ch;
  x = 0;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar())
    ;
}
int Cmp1(const node &i, const node &j) { return i.Y < j.Y; }
int Cmp2(const node &i, const node &j) { return i.X < j.X; }
int Max(int a, int b) {
  if (a > b) return a;
  return b;
}
int getfather(int i) {
  if (fa[i] == i) return i;
  fa[i] = getfather(fa[i]);
  return fa[i];
}
void Updata(tree &a, tree b, tree c) {
  a.g2 = Max(b.g1, b.g2) + Max(c.g1, c.g2);
  a.g1 = Max(b.g2 + Max(c.g1, c.g2), Max(b.g1, b.g2) + c.g2) + 1;
}
tree Query(int t, int l, int r) {
  tree G1, G2, G3;
  if (!t) return G[t];
  if (P[L[t]].X >= l && P[L[t] - 1].X < l && P[R[t]].X <= r &&
      P[R[t] + 1].X > r)
    return G[t];
  if (P[t].X > r) return Query(Lp[t], l, r);
  if (P[t].X < l) return Query(Rp[t], l, r);
  G1 = Query(Lp[t], l, P[R[Lp[t]]].X);
  G2 = Query(Rp[t], P[L[Rp[t]]].X, r);
  Updata(G3, G1, G2);
  return G3;
}
int main() {
  read(N), read(K);
  for (i = 1; i <= K; ++i) read(P[i].X), read(P[i].Y);
  read(A), read(B), read(C), read(D);
  for (i = K + 1; i <= N; ++i) {
    P[i].X = ((long long)A * P[i - 1].X + B) % oo;
    P[i].Y = ((long long)C * P[i - 1].Y + D) % oo;
  }
  sort(P + 1, P + N + 1, Cmp1);
  for (i = 1; i <= N; ++i) P[i].H = i;
  sort(P + 1, P + N + 1, Cmp2);
  for (i = 1; i <= N; ++i) S[P[i].H] = i;
  for (i = 1; i <= N; ++i) fa[i] = i;
  G[0].g2 = -oo;
  P[0].X = -1, P[N + 1].X = oo + 1;
  for (i = 1; i <= N; ++i) {
    if (f[S[i] - 1]) {
      Lp[S[i]] = u = getfather(S[i] - 1);
      L[S[i]] = L[u], fa[u] = S[i];
    } else
      Lp[S[i]] = 0, L[S[i]] = S[i];
    if (f[S[i] + 1]) {
      Rp[S[i]] = v = getfather(S[i] + 1);
      R[S[i]] = R[v], fa[v] = S[i];
    } else
      Rp[S[i]] = 0, R[S[i]] = S[i];
    Updata(G[S[i]], G[Lp[S[i]]], G[Rp[S[i]]]);
    f[S[i]] = 1;
  }
  read(M);
  for (i = 1; i <= M; ++i) {
    read(l), read(r);
    res = Query(S[N], l, r);
    printf("%d\n", Max(res.g1, res.g2));
  }
  return 0;
}
