#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 9;
int L[120000], R[120000], ml[120000], mr[120000], q[120000], tot, l, r, n, k, i,
    A, B, C, D, m;
pair<int, int> a[120000], f[120000], ans;
void dfs(int x) {
  if (L[x]) {
    dfs(L[x]);
    ml[x] = ml[L[x]];
  } else
    ml[x] = a[x].first;
  if (R[x]) {
    dfs(R[x]);
    mr[x] = mr[R[x]];
  } else
    mr[x] = a[x].first;
  f[x].first = f[L[x]].second + f[R[x]].second;
  f[x].second = max(
      max(f[L[x]].first + f[R[x]].second, f[L[x]].second + f[R[x]].first) + 1,
      f[x].first);
}
pair<int, int> work(int x) {
  if (!x) return make_pair(-10000000, 0);
  if (a[x].first < l) return work(R[x]);
  if (a[x].first > r) return work(L[x]);
  if (ml[x] >= l && mr[x] <= r) return f[x];
  pair<int, int> a = work(L[x]), b = work(R[x]), c;
  c.first = a.second + b.second;
  c.second = max(max(a.first + b.second, a.second + b.first) + 1, c.first);
  return c;
}
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  scanf("%d%d%d%d", &A, &B, &C, &D);
  for (i = k + 1; i <= n; ++i) {
    a[i].first = (1ll * A * a[i - 1].first + B) % mo;
    a[i].second = (1ll * C * a[i - 1].second + D) % mo;
  }
  sort(a + 1, a + n + 1);
  tot = 0;
  for (i = 1; i <= n; ++i) {
    while (tot && a[i].second > a[q[tot]].second) tot--;
    L[i] = q[tot + 1];
    R[q[tot]] = i;
    q[++tot] = i;
    q[tot + 1] = 0;
  }
  f[0] = make_pair(-1000000, 0);
  dfs(q[1]);
  scanf("%d", &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &l, &r);
    ans = work(q[1]);
    printf("%d\n", ans.second);
  }
}
