#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 100100;
const long long MOD = INF + 9;
struct node {
  long long x, y;
  node *l, *r;
  int value[2];
  node() {}
  node(long long x, long long y) {
    this->x = x;
    this->y = y;
    l = r = 0;
    value[0] = value[1] = 0;
  }
};
int getValue(node *v, int type) {
  if (v == 0) return 0;
  return v->value[type];
}
int getMaxValue(node *v) {
  if (v == 0) return 0;
  return max(v->value[0], v->value[1]);
}
void recalc(node *v) {
  if (v == 0) return;
  v->value[1] = 0;
  v->value[0] = getMaxValue(v->l) + getMaxValue(v->r);
  if (v->l != 0)
    v->value[1] = max(v->value[1], getValue(v->l, 0) + getMaxValue(v->r) + 1);
  if (v->r != 0)
    v->value[1] = max(v->value[1], getValue(v->r, 0) + getMaxValue(v->l) + 1);
}
void split(node *v, long long x, node *&l, node *&r) {
  if (v == 0) {
    l = r = 0;
    return;
  }
  if (x < v->x) {
    split(v->l, x, l, v->l);
    r = v;
  } else {
    split(v->r, x, v->r, r);
    l = v;
  }
  recalc(v);
  recalc(l);
  recalc(r);
}
node *merge(node *l, node *r) {
  if (l == 0) return r;
  if (r == 0) return l;
  if (l->y > r->y) {
    l->r = merge(l->r, r);
    recalc(l);
    recalc(r);
    return l;
  } else {
    r->l = merge(l, r->l);
    recalc(l);
    recalc(r);
    return r;
  }
}
pair<long long, long long> a[MAXN];
node *root;
int n, k, m;
int get(long long l, long long r) {
  node *left, *middle, *right;
  split(root, l - 1, left, middle);
  split(middle, r, middle, right);
  int ans = max(getValue(middle, 0), getValue(middle, 1));
  root = merge(left, merge(middle, right));
  return ans;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < (int)(k); i++) cin >> a[i].first >> a[i].second;
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  for (int i = k; i < n; i++) {
    a[i].first = (A * a[i - 1].first + B) % MOD;
    a[i].second = (C * a[i - 1].second + D) % MOD;
  }
  sort(a, a + n);
  for (int i = 0; i < (int)(n); i++)
    root = merge(root, new node(a[i].first, a[i].second));
  cin >> m;
  for (int query = 0; query < (int)(m); query++) {
    long long l, r;
    scanf("%I64d%I64d", &l, &r);
    printf("%d\n", get(l, r));
  }
  return 0;
}
