#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000009, mm = 100010;
int t, n, m, k, L, R, top, stk[mm], l[mm], r[mm];
pair<int, int> p[mm], f[mm], rg[mm];
pair<int, int> ask(int t, int L, int R) {
  if ((!t) || (L > rg[t].second) || (R < rg[t].first)) return make_pair(-1, 0);
  if ((L <= rg[t].first) && (R >= rg[t].second)) return f[t];
  pair<int, int> le, ri;
  le = ask(l[t], L, R);
  ri = ask(r[t], L, R);
  if ((p[t].first <= R) && (p[t].first >= L))
    return make_pair(le.second + ri.second,
                     max(le.first + ri.second, le.second + ri.first) + 1);
  else
    return le.first < 0 ? ri : le;
}
void make(int t, int L, int R) {
  if (!t) return;
  make(l[t], L, t - 1);
  make(r[t], t + 1, R);
  rg[t].first = p[L].first;
  rg[t].second = p[R].first;
  pair<int, int> le, ri;
  le = l[t] ? f[l[t]] : make_pair(-1, 0);
  ri = r[t] ? f[r[t]] : make_pair(-1, 0);
  f[t].first = le.second + ri.second;
  f[t].second = max(le.first + ri.second, le.second + ri.first) + 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) scanf("%d%d", &p[i].first, &p[i].second);
  int x1, x2, x3, x4;
  scanf("%d%d%d%d", &x1, &x2, &x3, &x4);
  for (int i = k + 1; i <= n; i++) {
    p[i].first = (1LL * p[i - 1].first * x1 % mo + x2) % mo;
    p[i].second = (1LL * p[i - 1].second * x3 % mo + x4) % mo;
  }
  sort(p + 1, p + n + 1);
  stk[top = 1] = t = 1;
  for (int i = 2; i <= n; i++) {
    while ((top > 0) && (p[stk[top]].second < p[i].second)) top--;
    if (top > 0) {
      l[i] = r[stk[top]];
      r[stk[top]] = i;
    } else {
      t = i;
      l[i] = stk[1];
    }
    stk[++top] = i;
  }
  make(t, 1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &L, &R);
    printf("%d\n", ask(t, L, R).second);
  }
}
