#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
const int MOD = 1e9 + 9;
int n, k, a, b, c, d, m, L, R, tot = 1;
pair<int, int> cities[MAXN];
struct TreeNode {
  int x, l, r, lson, rson;
  pair<int, int> v;
} tree[MAXN];
int newNode(int &x) { return x = ++tot; }
pair<int, int> calc(pair<int, int> l, pair<int, int> r) {
  return {l.second + r.second, max(l.first + r.second, l.second + r.first) + 1};
}
void build(int o, int l, int r) {
  int max_y = -1, max_id = l;
  for (int i = l; i <= r; i++) {
    if (cities[i].second > max_y) {
      max_y = cities[i].second;
      max_id = i;
    }
  }
  tree[o].l = cities[l].first;
  tree[o].r = cities[r].first;
  tree[o].x = cities[max_id].first;
  if (l < max_id) build(newNode(tree[o].lson), l, max_id - 1);
  if (max_id < r) build(newNode(tree[o].rson), max_id + 1, r);
  tree[o].v = calc(tree[tree[o].lson].v, tree[tree[o].rson].v);
}
pair<int, int> query(int o, int l, int r) {
  if (o == 0 || l > tree[o].r || r < tree[o].l) return {-1, 0};
  if (l <= tree[o].l && tree[o].r <= r) return tree[o].v;
  if (r < tree[o].x) return query(tree[o].lson, l, r);
  if (l > tree[o].x) return query(tree[o].rson, l, r);
  return calc(query(tree[o].lson, l, r), query(tree[o].rson, l, r));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &cities[i].first, &cities[i].second);
  }
  scanf("%d%d%d%d", &a, &b, &c, &d);
  for (int i = k; i < n; i++) {
    cities[i].first = (1LL * a * cities[i - 1].first + b) % MOD;
    cities[i].second = (1LL * c * cities[i - 1].second + d) % MOD;
  }
  sort(cities, cities + n);
  tree[0].v = {-1, 0};
  build(1, 0, n - 1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &L, &R);
    printf("%d\n", query(1, L, R).second);
  }
}
