#include <bits/stdc++.h>
using std::max;
using std::pair;
const int maxn = 1000010, maxk = 19;
const int P = 1000000009;
int n;
pair<int, int> a[maxn];
int w[maxn][maxk];
int l[maxn], r[maxn], lb[maxn], rb[maxn];
pair<int, int> f[maxn];
inline int gmax(const int &x, const int &y) {
  return a[x].second > a[y].second ? x : y;
}
int build(int x, int y) {
  int k = (int)(log((double)y - x + 1) / log(2.));
  int p = gmax(w[x][k], w[y - (1 << k) + 1][k]);
  lb[p] = x, rb[p] = y;
  if (x != p) l[p] = build(x, p - 1);
  if (y != p) r[p] = build(p + 1, y);
  return p;
}
inline int max(const pair<int, int> &a) { return max(a.first, a.second); }
inline pair<int, int> operator+(const pair<int, int> &a,
                                const pair<int, int> &b) {
  return pair<int, int>(1 + max(a.second + max(b), b.second + max(a)),
                        max(a) + max(b));
}
pair<int, int> sol(int k) {
  if (k) f[k] = sol(l[k]) + sol(r[k]);
  return f[k];
}
pair<int, int> sol(int k, int x, int y) {
  if (!k) return f[0];
  if (lb[k] >= x && rb[k] <= y) return f[k];
  if (k < x) return sol(r[k], x, y);
  if (k > y) return sol(l[k], x, y);
  return sol(r[k], x, y) + sol(l[k], x, y);
}
int main() {
  int k, A, B, C, D, m, i, j, q, x, y, R;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  scanf("%d%d%d%d", &A, &B, &C, &D);
  for (i = k + 1; i <= n; ++i)
    a[i].first = ((long long)A * a[i - 1].first + B) % P,
    a[i].second = ((long long)C * a[i - 1].second + D) % P;
  sort(a + 1, a + n + 1);
  for (m = 0; (1 << m) <= n; ++m)
    ;
  for (i = 1; i <= n; ++i) w[i][0] = i;
  for (j = 1; j < m; ++j)
    for (i = 1; i + (1 << j) - 1 <= n; ++i)
      w[i][j] = gmax(w[i][j - 1], w[i + (1 << j - 1)][j - 1]);
  R = build(1, n);
  f[0] = pair<int, int>(0, -1), sol(R);
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &x, &y);
    x = lower_bound(a + 1, a + n + 1, pair<int, int>(x, 0)) - a;
    y = lower_bound(a + 1, a + n + 1, pair<int, int>(y + 1, 0)) - a - 1;
    printf("%d\n", max(sol(R, x, y)));
  }
  return 0;
}
