#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10, MOD = (int)1e9 + 9;
int a, b, c, d, top, v[MAXN], vl[MAXN], vr[MAXN], l[MAXN], r[MAXN], n, m, k,
    st[MAXN];
pair<int, int> f[MAXN], p[MAXN];
pair<int, int> calc(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.second + b.second,
                   max(a.first + b.second, a.second + b.first) + 1);
}
void DFS(int first) {
  if (!first) return;
  DFS(l[first]), DFS(r[first]);
  f[first] = calc(f[l[first]], f[r[first]]);
  v[first] = p[first].first, vl[first] = l[first] ? vl[l[first]] : v[first];
  vr[first] = r[first] ? vr[r[first]] : v[first];
}
pair<int, int> Query(int first, int L, int R) {
  if (!first || vl[first] > R || vr[first] < L) return f[0];
  if (L <= vl[first] && vr[first] <= R) return f[first];
  if (R < v[first]) return Query(l[first], L, R);
  if (v[first] < L) return Query(r[first], L, R);
  return calc(Query(l[first], L, R), Query(r[first], L, R));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    int first, second;
    scanf("%d%d", &first, &second);
    p[i] = make_pair(first, second);
  }
  scanf("%d%d%d%d", &a, &b, &c, &d);
  for (int i = k + 1; i <= n; ++i)
    p[i] = make_pair(((long long)p[i - 1].first * a + b) % MOD,
                     ((long long)p[i - 1].second * c + d) % MOD);
  sort(p + 1, p + n + 1);
  f[0] = make_pair(-1, 0);
  top = 1;
  st[1] = 0;
  for (int i = 1; i <= n; ++i) {
    while (top >= 1 && p[i].second >= p[st[top]].second) --top;
    r[st[top]] = i;
    l[i] = st[++top];
    st[top] = i;
    st[top + 1] = 0;
  }
  DFS(r[0]);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int first, second;
    scanf("%d%d", &first, &second);
    printf("%d\n", Query(r[0], first, second).second);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
