#include <bits/stdc++.h>
using namespace std;
const int NN = 101010, mod = 1000000009;
pair<int, int> p[NN];
int lft_sun[NN];
int rgt_sun[NN];
int pre[NN][2];
int id[NN];
int t1[NN];
int t2[NN];
int pre_calc(int l, int r) {
  if (l > r) return -1;
  int u = id[l];
  if (l == r) {
    lft_sun[u] = rgt_sun[u] = -1;
    pre[u][0] = pre[u][1] = 0;
    return u;
  }
  int s = 0, t = 0;
  for (int i = l + 1; i <= r; i++) {
    if (p[id[i]].first < p[u].first)
      t1[s++] = id[i];
    else
      t2[t++] = id[i];
  }
  for (int i = l; i < l + s; i++) id[i] = t1[i - l];
  id[l + s] = u;
  for (int i = l + s + 1; i <= r; i++) id[i] = t2[i - l - s - 1];
  int lc = pre_calc(l, l + s - 1);
  int rc = pre_calc(l + s + 1, r);
  lft_sun[u] = lc;
  rgt_sun[u] = rc;
  pre[u][0] = (lc >= 0 ? pre[lc][1] : 0) + (rc >= 0 ? pre[rc][1] : 0);
  pre[u][1] = max((lc >= 0 ? 1 + pre[lc][0] : 0) + (rc >= 0 ? pre[rc][1] : 0),
                  (lc >= 0 ? pre[lc][1] : 0) + (rc >= 0 ? 1 + pre[rc][0] : 0));
  pre[u][1] = max(pre[u][1], pre[u][0]);
  return u;
}
int dyna[NN][2];
void calc(int u, int L, int R, int st, int ed) {
  if (L >= st && R <= ed) {
    dyna[u][0] = pre[u][0];
    dyna[u][1] = pre[u][1];
    return;
  }
  if (p[u].first < st) {
    if (~rgt_sun[u]) calc(rgt_sun[u], p[u].first + 1, R, st, ed);
    if (rgt_sun[u] >= 0) {
      dyna[u][0] = dyna[rgt_sun[u]][0];
      dyna[u][1] = dyna[rgt_sun[u]][1];
    } else
      dyna[u][0] = -1, dyna[u][1] = 0;
    return;
  }
  if (p[u].first > ed) {
    if (~lft_sun[u]) calc(lft_sun[u], L, p[u].first - 1, st, ed);
    if (lft_sun[u] >= 0) {
      dyna[u][0] = dyna[lft_sun[u]][0];
      dyna[u][1] = dyna[lft_sun[u]][1];
    } else
      dyna[u][0] = -1, dyna[u][1] = 0;
    return;
  }
  int LY = -1, LN = 0, RY = -1, RN = 0;
  if (~lft_sun[u]) {
    calc(lft_sun[u], L, p[u].first - 1, st, ed);
    LY = dyna[lft_sun[u]][0];
    LN = dyna[lft_sun[u]][1];
  }
  if (~rgt_sun[u]) {
    calc(rgt_sun[u], p[u].first + 1, R, st, ed);
    RY = dyna[rgt_sun[u]][0];
    RN = dyna[rgt_sun[u]][1];
  }
  dyna[u][0] = max(LY, LN) + max(RY, RN);
  dyna[u][1] = max(LY + 1 + RN, RY + 1 + LN);
  if (dyna[u][0] > dyna[u][1]) {
    dyna[u][1] = dyna[u][0];
  }
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    id[i] = 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 + 1; i <= n; i++) {
    p[i].first = ((long long)A * p[i - 1].first + B) % mod;
    p[i].second = ((long long)C * p[i - 1].second + D) % mod;
    id[i] = i;
  }
  sort(id + 1, id + n + 1,
       [](int a, int b) { return p[a].second > p[b].second; });
  int root = id[1];
  pre_calc(1, n);
  int m;
  scanf("%d", &m);
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    calc(root, 0, mod - 1, l, r);
    printf("%d\n", dyna[root][1]);
  }
  return 0;
}
