#include <bits/stdc++.h>
using namespace std;
const int md = (int)1e9 + 9;
int n, k;
pair<int, int> p[1000000];
int kv, root;
int first[1000000];
int second[1000000];
int L[1000000];
int R[1000000];
int dp0[1000000];
int dp1[1000000];
void recalc(int v) {
  if (v == 0) return;
  dp0[v] = max(dp0[L[v]], dp1[L[v]]) + max(dp0[R[v]], dp1[R[v]]);
  dp1[v] = -1e9;
  if (L[v] > 0) dp1[v] = max(dp1[v], dp0[L[v]] + max(dp0[R[v]], dp1[R[v]]) + 1);
  if (R[v] > 0) dp1[v] = max(dp1[v], dp0[R[v]] + max(dp0[L[v]], dp1[L[v]]) + 1);
}
int mergee(int a, int b) {
  if (a == 0 || b == 0) return a + b;
  if (second[a] < second[b]) {
    L[b] = mergee(a, L[b]);
    recalc(b);
    return b;
  }
  R[a] = mergee(R[a], b);
  recalc(a);
  return a;
}
void split(int v, int X, int& lf, int& rg) {
  lf = 0;
  rg = 0;
  if (v == 0) return;
  int gg;
  if (first[v] <= X) {
    split(R[v], X, gg, rg);
    R[v] = gg;
    lf = v;
  } else {
    split(L[v], X, lf, gg);
    L[v] = gg;
    rg = v;
  }
  recalc(lf);
  recalc(rg);
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &p[i].first, &p[i].second);
  }
  int A, B, C, D;
  scanf("%d %d %d %d", &A, &B, &C, &D);
  for (int i = k; i < n; i++) {
    p[i].first = ((long long)A * p[i - 1].first + B) % md;
    p[i].second = ((long long)C * p[i - 1].second + D) % md;
  }
  sort(p, p + n);
  root = 0;
  kv = 0;
  for (int i = 0; i < n; i++) {
    kv++;
    first[kv] = p[i].first;
    second[kv] = p[i].second;
    L[kv] = 0;
    R[kv] = 0;
    dp0[kv] = 0;
    dp1[kv] = -1e9;
    root = mergee(root, kv);
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int l, r, lf, md, rg;
    scanf("%d %d", &l, &r);
    split(root, r, md, rg);
    split(md, l - 1, lf, md);
    printf("%d\n", max(dp0[md], dp1[md]));
    lf = mergee(lf, md);
    root = mergee(lf, rg);
  }
  return 0;
}
