#include <bits/stdc++.h>
using namespace std;
struct Point {
  long long x, y;
  friend bool operator<(const Point &a, const Point &b) { return a.x < b.x; }
} p[100010];
pair<int, int> F[100010];
int n, Root, lc[100010], rc[100010], tot;
long long x[100010], y[100010], minx[100010], maxx[100010];
bool cmp(const Point &a, const Point &b) { return a.y < b.y; }
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  pair<int, int> ans;
  ans.first = max(a.first, a.second) + max(b.first, b.second);
  ans.second = max(max(a.first, a.second) + b.first + 1,
                   a.first + 1 + max(b.first, b.second));
  return ans;
}
void read() {
  F[0] = make_pair(-1 << 30, 0);
  int k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) cin >> p[i].x >> p[i].y;
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int i = k + 1; i <= n; ++i) {
    p[i].x = (a * p[i - 1].x + b) % 1000000009;
    p[i].y = (c * p[i - 1].y + d) % 1000000009;
  }
  sort(p + 1, p + n + 1);
}
int NewNode(int lson, int rson, const Point &p) {
  ++tot;
  lc[tot] = lson, rc[tot] = rson;
  F[tot] = F[lson] + F[rson];
  x[tot] = minx[tot] = maxx[tot] = p.x, y[tot] = p.y;
  if (lson) minx[tot] = minx[lson];
  if (rson) maxx[tot] = maxx[rson];
  return tot;
}
int Build(int l, int r) {
  if (l > r) return 0;
  if (l == r) {
    ++tot;
    x[tot] = p[l].x, y[tot] = p[l].y;
    minx[tot] = p[l].x, maxx[tot] = p[l].x;
    return tot;
  }
  int num = max_element(p + l, p + r + 1, cmp) - p;
  return NewNode(Build(l, num - 1), Build(num + 1, r), p[num]);
}
pair<int, int> Query(int Root, int L, int R) {
  if (Root == 0) return F[Root];
  if (minx[Root] >= L && maxx[Root] <= R) return F[Root];
  if (x[Root] > R)
    return Query(lc[Root], L, R);
  else if (x[Root] < L)
    return Query(rc[Root], L, R);
  else
    return Query(lc[Root], L, x[Root]) + Query(rc[Root], x[Root], R);
}
void Query() {
  int test, L, R;
  for (cin >> test; test; --test) {
    cin >> L >> R;
    pair<int, int> ans = Query(Root, L, R);
    printf("%d\n", max(ans.first, ans.second));
  }
}
int main() {
  read();
  Root = Build(1, n);
  Query();
  return 0;
}
