#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 50, modu = int(1e9) + 9;
struct state {
  int f, g;
  state(int ff, int gg) : f(ff), g(gg) {}
  static state null() { return state(0, -N); }
  static state single() { return state(0, 0); }
};
state operator+(const state &a, const state &b) {
  return state(max(a.g + max(b.f, b.g), max(a.f, a.g) + b.g) + 1,
               max(a.f, a.g) + max(b.f, b.g));
}
struct tree {
  pair<int, int> *arr;
  int l, r, maxpos;
  state s;
  tree *lc, *rc;
  tree(int _l, int _r, pair<int, int> *a)
      : l(_l), r(_r), arr(a), lc(0), rc(0), s(state::single()) {}
  static state gstate(tree *t) { return t ? t->s : state::null(); }
  void init() {
    maxpos = r;
    for (int i = l; i < r; ++i)
      if (arr[i].second > arr[maxpos].second) maxpos = i;
    if (l == r) return;
    if (maxpos != l) (lc = new tree(l, maxpos - 1, arr))->init();
    if (maxpos != r) (rc = new tree(maxpos + 1, r, arr))->init();
    s = gstate(lc) + gstate(rc);
  }
  state query(int xl, int xr) {
    if (xl > arr[r].first || xr < arr[l].first) return state::null();
    if (xl <= arr[l].first && arr[r].first <= xr) return s;
    if (xr < arr[maxpos].first) return lc ? lc->query(xl, xr) : state::null();
    if (xl > arr[maxpos].first) return rc ? rc->query(xl, xr) : state::null();
    state rl = state::null(), rr = state::null();
    if (lc) rl = lc->query(xl, xr);
    if (rc) rr = rc->query(xl, xr);
    return rl + rr;
  }
} * rt;
pair<int, int> A[N];
int n;
int main() {
  int k, m, a, b, c, d;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) scanf("%d%d", &A[i].first, &A[i].second);
  scanf("%d%d%d%d", &a, &b, &c, &d);
  for (int i = k + 1; i <= n; ++i) {
    A[i].first = ((long long)a * A[i - 1].first + b) % modu;
    A[i].second = ((long long)c * A[i - 1].second + d) % modu;
  }
  sort(A + 1, A + 1 + n);
  (rt = new tree(1, n, A))->init();
  scanf("%d", &m);
  while (m--) {
    int xl, xr;
    scanf("%d%d", &xl, &xr);
    state r = rt->query(xl, xr);
    printf("%d\n", max(r.f, r.g));
  }
  return 0;
}
