#include <bits/stdc++.h>
using namespace std;
int n, m;
bool debug = false;
int k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int mod = 1000000009;
pair<int, int> p[100005];
struct node {
  int l, r, Lnode, Rnode, s;
  pair<int, int> v;
} nd[100005];
pair<int, int> merge(pair<int, int> x, pair<int, int> y) {
  return {x.second + y.second, 1 + max(x.first + y.second, y.first + x.second)};
}
int merge(int x, int y) {
  int s = 0;
  s += x + 1 + y + 1;
  return s;
}
int build(int l, int r) {
  int j = l;
  for (int i = l; i <= r; i++) {
    if (p[i].second > p[j].second ||
        (p[i].second == p[j].second && p[i].first > p[j].first)) {
      j = i;
    }
  }
  nd[j].Lnode = j > l ? build(l, j - 1) : 0;
  nd[j].Rnode = j < r ? build(j + 1, r) : 0;
  nd[j].v = merge(nd[nd[j].Lnode].v, nd[nd[j].Rnode].v);
  nd[j].s = merge(nd[nd[j].Lnode].s, nd[nd[j].Rnode].s);
  nd[j].l = j > l ? nd[nd[j].Lnode].l : p[l].first;
  nd[j].r = j < r ? nd[nd[j].Rnode].r : p[r].first;
  return j;
}
pair<int, int> query(int x, int l, int r) {
  if (x == 0 || (nd[x].l >= l && nd[x].r <= r)) return nd[x].v;
  if (p[x].first < l) return query(nd[x].Rnode, l, r);
  if (p[x].first > r) return query(nd[x].Lnode, l, r);
  return merge(query(nd[x].Lnode, l, r), query(nd[x].Rnode, l, r));
}
int query1(int x, int l, int r) {
  if (x == 0 || (nd[x].l >= l && nd[x].r <= r)) return nd[x].s;
  if (p[x].first < l) return query1(nd[x].Rnode, l, r);
  if (p[x].first > r) return query1(nd[x].Lnode, l, r);
  return merge(query1(nd[x].Lnode, l, r), query1(nd[x].Rnode, l, r));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
  }
  nd[0].v = {-1, 0};
  nd[0].s = -1;
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  for (int i = k + 1; i <= n; i++) {
    p[i] = {((long long)a * p[i - 1].first + b) % mod,
            ((long long)c * p[i - 1].second + d) % mod};
  }
  sort(p + 1, p + 1 + n);
  int root = build(1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &a, &b);
    printf("%d\n", query(root, a, b).second);
  }
  return 0;
}
