#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct CartesianTree {
  int n, root;
  vector<pair<int, int>> dp;
  vector<int> min, max, left, right;
  vector<pair<ll, ll>> points;
  CartesianTree(int n, vector<pair<ll, ll>>& points)
      : n(n), points(points), dp(n), min(n), max(n), left(n, -1), right(n, -1) {
    sort(this->points.begin(), this->points.end());
    for (auto& p : this->points) {
      swap(p.first, p.second);
    }
    root = build(0, n - 1);
  }
  int build(int l, int r) {
    int m = max_element(points.begin() + l, points.begin() + r + 1) -
            points.begin();
    min[m] = points[l].second;
    max[m] = points[r].second;
    pair<int, int> p = {0, numeric_limits<int>::min()},
                   q = {0, numeric_limits<int>::min()};
    if (l < m) {
      left[m] = build(l, m - 1);
      p = dp[left[m]];
    }
    if (m < r) {
      right[m] = build(m + 1, r);
      q = dp[right[m]];
    }
    dp[m] = {std::max(std::max(p.first, p.second) + q.second + 1,
                      p.second + std::max(q.first, q.second) + 1),
             std::max(p.first, p.second) + std::max(q.first, q.second)};
    return m;
  }
  pair<int, int> query(int at, int l, int r) {
    pair<int, int> res;
    if (at == -1 || r < min[at] || max[at] < l) {
      res = {0, numeric_limits<int>::min()};
    } else if (l <= min[at] && max[at] <= r) {
      res = dp[at];
    } else if (r < points[at].second) {
      res = query(left[at], l, r);
    } else if (points[at].second < l) {
      res = query(right[at], l, r);
    } else {
      auto p = query(left[at], l, r);
      auto q = query(right[at], l, r);
      res = {std::max(std::max(p.first, p.second) + q.second + 1,
                      p.second + std::max(q.first, q.second) + 1),
             std::max(p.first, p.second) + std::max(q.first, q.second)};
    }
    return res;
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> points(n);
  for (int i = 0; i < k; i++) {
    cin >> points[i].first >> points[i].second;
  }
  ll a, b, c, d, mod = 1000000009;
  cin >> a >> b >> c >> d;
  for (int i = k; i < n; i++) {
    points[i].first = (a * points[i - 1].first + b) % mod;
    points[i].second = (c * points[i - 1].second + d) % mod;
  }
  CartesianTree T(n, points);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    auto p = T.query(T.root, l, r);
    cout << max(p.first, p.second) << endl;
    ;
  }
  return 0;
}
