#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> data[100010];
int get(int x, bool flag) {
  int g = 0, h = n - 1, ret = flag ? -1 : n;
  while (g <= h) {
    int mid = (g + h) / 2;
    if (flag) {
      if (data[mid].first <= x)
        ret = mid, g = mid + 1;
      else
        h = mid - 1;
    } else {
      if (data[mid].first >= x)
        ret = mid, h = mid - 1;
      else
        g = mid + 1;
    }
  }
  return ret;
}
struct Key {
  int f, g;
  Key(int _x = 0, int _y = 0) : f(_x), g(_y) {}
  Key operator+(const Key &a) {
    return Key(max(f + a.g + 1, g + a.f + 1), f + a.f);
  }
  Key add() { return Key(max(f, g + 1), f); }
} zero;
struct Node {
  Node *lc, *rc;
  int mid, left, right;
  Key key;
  Node() { lc = rc = 0; }
} * root;
Node *build(int l, int r) {
  if (l > r) return NULL;
  Node *root = new Node();
  root->left = l, root->right = r;
  int k = l;
  for (int i = l + 1; i <= r; i++)
    if (data[i].second > data[k].second) k = i;
  root->mid = k;
  root->lc = build(l, k - 1);
  root->rc = build(k + 1, r);
  if (root->lc && root->rc)
    root->key = root->lc->key + root->rc->key;
  else if (root->lc)
    root->key = root->lc->key.add();
  else if (root->rc)
    root->key = root->rc->key.add();
  else
    root->key = zero;
  return root;
}
void init() {
  int K, a, b, c, d;
  scanf("%d%d", &n, &K);
  for (int i = 0; i < K; i++) scanf("%d%d", &data[i].first, &data[i].second);
  scanf("%d%d%d%d", &a, &b, &c, &d);
  for (int i = K; i < n; i++)
    data[i].first = (((long long)a * data[i - 1].first) + b) % 1000000009,
    data[i].second = (((long long)c * data[i - 1].second) + d) % 1000000009;
  sort(data, data + n);
  root = build(0, n - 1);
}
Key ask(Node *root, int l, int r) {
  if (root->left == l && root->right == r) return root->key;
  if (l == r) return zero;
  int mid = root->mid;
  if (r < mid) return ask(root->lc, l, r);
  if (l > mid) return ask(root->rc, l, r);
  if (r == mid) return ask(root->lc, l, r - 1).add();
  if (l == mid) return ask(root->rc, l + 1, r).add();
  return ask(root->lc, l, mid - 1) + ask(root->rc, mid + 1, r);
}
int main() {
  init();
  int m, l, r;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &l, &r);
    l = get(l, 0);
    r = get(r, 1);
    if (l > r) {
      printf("0\n");
      continue;
    }
    Key ans = ask(root, l, r);
    printf("%d\n", max(ans.f, ans.g));
  }
  return 0;
}
