#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000009;
const int MaxN = 100010;
int n, k, m;
pair<int, int> a[MaxN], f[MaxN];
int h[MaxN], lc[MaxN], rc[MaxN], l[MaxN], r[MaxN], p[MaxN];
inline pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.second + b.second,
                        max(a.first + b.second, a.second + b.first) + 1);
}
void init() {
  long long A, B, C, D;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) scanf("%d%d", &a[i].first, &a[i].second);
  scanf("%I64d%I64d%I64d%I64d", &A, &B, &C, &D);
  for (int i = k + 1; i <= n; i++)
    a[i].first = int((A * a[i - 1].first + B) % MOD),
    a[i].second = int((C * a[i - 1].second + D) % MOD);
  sort(a + 1, a + n + 1);
  int t = 1;
  for (int i = 1; i <= n; i++) {
    while (t && a[i].second >= a[h[t]].second) t--;
    rc[h[t]] = i;
    lc[i] = h[++t];
    h[t] = i;
    h[t + 1] = 0;
  }
}
void dfs(int u) {
  if (!u) return;
  dfs(lc[u]);
  dfs(rc[u]);
  f[u] = merge(f[lc[u]], f[rc[u]]);
  p[u] = a[u].first;
  l[u] = lc[u] ? l[lc[u]] : p[u];
  r[u] = rc[u] ? r[rc[u]] : p[u];
}
pair<int, int> query(int u, int L, int R) {
  if (!u || l[u] > R || r[u] < L) return f[0];
  if (L <= l[u] && R >= r[u]) return f[u];
  if (L > p[u])
    return query(rc[u], L, R);
  else if (R < p[u])
    return query(lc[u], L, R);
  else
    return merge(query(lc[u], L, R), query(rc[u], L, R));
}
int main() {
  init();
  f[0] = pair<int, int>(-1, 0);
  dfs(rc[0]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", query(rc[0], l, r).second);
  }
  return 0;
}
