#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> a[(220000)];
int rmq[(220000)][20], maxl, root, son[(220000)][2], f[(220000)][2],
    le[(220000)], ri[(220000)];
void pre_RMQ() {
  maxl = (int)(log(n) / log(2));
  memset(rmq, -1, sizeof(rmq));
  for (int i = (1); i <= (n); i++) rmq[i][0] = i;
  for (int l = (0); l <= (maxl - 1); l++)
    for (int i = (1); i <= (n); i++) {
      rmq[i][l + 1] = rmq[i + (1 << l)][l];
      if (rmq[i][l] != -1 && (rmq[i][l + 1] == -1 ||
                              a[rmq[i][l]].second > a[rmq[i][l + 1]].second))
        rmq[i][l + 1] = rmq[i][l];
    }
}
int get(int l, int r) {
  if (l > r) return -1;
  if (l == r) return l;
  int len = (int)(log(r - l + 1) / log(2));
  int ret = rmq[r - (1 << len) + 1][len];
  if (rmq[l][len] != -1 && (ret == -1 || a[rmq[l][len]].second > a[ret].second))
    return rmq[l][len];
  return ret;
}
int build(int l, int r, int father) {
  if (l > r) return -1;
  int root = get(l, r);
  son[root][0] = build(l, root - 1, root);
  son[root][1] = build(root + 1, r, root);
  le[root] = a[l].first, ri[root] = a[r].first;
  l = son[root][0], r = son[root][1];
  if (l == -1 && r == -1) return f[root][1] = f[root][0] = 0, root;
  if (l == -1)
    return f[root][0] = max(f[r][0], f[r][1] + 1), f[root][1] = f[r][0], root;
  if (r == -1)
    return f[root][0] = max(f[l][0], f[l][1] + 1), f[root][1] = f[l][0], root;
  f[root][1] = f[l][0] + f[r][0];
  f[root][0] = max(f[root][1], 1 + max(f[l][0] + f[r][1], f[l][1] + f[r][0]));
  return root;
}
pair<int, int> dfs(int root, int l, int r) {
  if (root == -1 || l > ri[root] || r < le[root]) return make_pair(0, -1);
  if (l <= le[root] && ri[root] <= r) return make_pair(f[root][0], f[root][1]);
  if (r < a[root].first) return dfs(son[root][0], l, r);
  if (a[root].first < l) return dfs(son[root][1], l, r);
  pair<int, int> ff, f1 = dfs(son[root][0], l, r), f2 = dfs(son[root][1], l, r);
  ff.second = f1.first + f2.first;
  ff.first = ff.second;
  if (f1.second != -1) ff.first = max(ff.first, 1 + f1.second + f2.first);
  if (f2.second != -1) ff.first = max(ff.first, 1 + f2.second + f1.first);
  return ff;
}
int main() {
  cin >> n >> k;
  for (int i = (1); i <= (k); i++) cin >> a[i].first >> a[i].second;
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  for (int i = (k + 1); i <= (n); i++)
    a[i].first = (A * a[i - 1].first + B) % (1000000009),
    a[i].second = (C * a[i - 1].second + D) % (1000000009);
  sort(a + 1, a + n + 1);
  pre_RMQ();
  root = build(1, n, -1);
  int m, l, r;
  cin >> m;
  while (m--) scanf("%d%d", &l, &r), printf("%d\n", dfs(root, l, r).first);
  return 0;
}
