#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
template <class S, class T>
inline pair<S, T> MP(S a, T b) {
  return make_pair(a, b);
}
template <class T>
inline auto LX(T &X) -> decltype((X.first)) {
  return X.first;
}
template <class T>
inline auto LX(const T &X) -> const decltype((X.first)) {
  return X.first;
}
template <class T>
inline auto RX(T &X) -> decltype((X.second)) {
  return X.second;
}
template <class T>
inline auto RX(const T &X) -> const decltype((X.second)) {
  return X.second;
}
template <class T>
inline void RST(T &a) {
  memset(a, 0, sizeof(a));
}
template <class T>
inline void RST1(T &a) {
  memset(a, -1, sizeof(a));
}
template <class T>
inline void SINF(T &a) {
  memset(a, 0x0f, sizeof(a));
}
template <class S, class T>
inline void RST(S &a, T b) {
  fill((T *)a, (T *)a + (sizeof(a) / sizeof(b)), b);
}
template <class T>
inline void CLR(T &a) {
  a.clear();
}
template <class S, class T>
inline void CPY(S &a, T &b) {
  memcpy(a, b, sizeof(a));
}
template <class S, class T>
inline bool chkmin(S &a, T b) {
  return b < a ? a = b, 1 : 0;
}
template <class S, class T>
inline bool chkmax(S &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline int SZ(T &a) {
  return (int)(a.size());
}
template <class T>
inline bool EPT(T &a) {
  return a.empty();
}
template <class T>
inline auto FRT(T &a) -> decltype((a.front())) {
  return a.front();
}
template <class T>
inline auto FRT(const T &a) -> const decltype((a.front())) {
  return a.front();
}
template <class T>
inline auto BK(T &a) -> decltype(a.back()) & {
  return a.back();
}
template <class T>
inline auto BK(const T &a) -> const decltype((a.back())) {
  return a.back();
}
template <class T>
inline auto TOP(T &a) -> decltype((a.top())) {
  return a.top();
}
template <class T>
inline auto TOP(const T &a) -> const decltype((a.top())) {
  return a.top();
}
int n, k;
pair<int, int> p[100010];
long long a, b, c, d;
const long long MOD = 1000000009;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return RX(a) < RX(b);
}
struct Tnode {
  int low, high, x;
  pair<int, int> dp;
  Tnode *l, *r;
  Tnode();
};
Tnode TPool[100010], *tp = TPool + 1, *nul = TPool;
Tnode::Tnode() : l(nul), r(nul) {}
inline Tnode *getnew(int i) {
  Tnode *ret = tp++;
  return ret->low = ret->high = ret->x = LX(p[i]), ret->dp = MP(0, 0), ret;
}
inline pair<int, int> comb(pair<int, int> a, pair<int, int> b) {
  return MP(RX(a) + RX(b), 1 + max(LX(a) + RX(b), RX(a) + LX(b)));
}
inline Tnode *getnew(Tnode *a, Tnode *b, int i) {
  Tnode *ret = tp++;
  int x = LX(p[i]);
  return ret->low = min(x, min(a->low, b->low)),
         ret->high = max(x, max(a->high, b->high)), ret->x = x,
         ret->dp = comb(a->dp, b->dp), ret->l = a, ret->r = b, ret;
}
Tnode *build(int l, int r) {
  if (l > r) return nul;
  if (l == r) return getnew(l);
  int i = max_element(p + l, p + r + 1, cmp) - p;
  return getnew(build(l, i - 1), build(i + 1, r), i);
}
Tnode *R;
pair<int, int> Query(Tnode *R, int lx, int rx) {
  if (R->low > rx || R->high < lx) return nul->dp;
  if (lx <= R->low && rx >= R->high) return R->dp;
  if (rx < R->x) return Query(R->l, lx, rx);
  if (lx > R->x) return Query(R->r, lx, rx);
  return comb(Query(R->l, lx, rx), Query(R->r, lx, rx));
}
int main() {
  nul->low = inf, nul->high = -inf, nul->dp = MP(-1, 0);
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) scanf("%d%d", &LX(p[i]), &RX(p[i]));
  scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d);
  for (int i = k + 1; i <= n; i++)
    p[i] = MP((LX(p[i - 1]) * a + b) % MOD, (RX(p[i - 1]) * c + d) % MOD);
  sort(p + 1, p + n + 1);
  R = build(1, n);
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    pair<int, int> ans = Query(R, l, r);
    printf("%d\n", max(LX(ans), RX(ans)));
  }
  return 0;
}
