In some country live wizards. They love to build cities and roads.

The country used to have k cities, the j-th city (1 ≤ j ≤ k) was located at a point (xj, yj). It was decided to create another n - k cities. And the i-th one (k < i ≤ n) was created at a point with coordinates (xi, yi):

  * xi = (a·xi - 1 + b) mod (109 + 9)
  * yi = (c·yi - 1 + d) mod (109 + 9)



Here a, b, c, d are primes. Also, a ≠ c, b ≠ d.

After the construction of all n cities, the wizards have noticed something surprising. It turned out that for every two different cities i and j, xi ≠ xj and yi ≠ yj holds.

The cities are built, it's time to build roads! It was decided to use the most difficult (and, of course, the most powerful) spell for the construction of roads. Using this spell creates a road between the towns of u, v (yu > yv) if and only if for any city w which lies strictly inside the corner at the point u, v (see below), there is a city s that does not lie in the corner, which is located along the x-coordinate strictly between w and u and simultaneously ys > yv.

A corner on the points p2(x2, y2), p1(x1, y1) (y1 < y2) is the set of points (x, y), for which at least one of the two conditions is fulfilled: 

  * min(x1, x2) ≤ x ≤ max(x1, x2) and y ≥ y1
  * y1 ≤ y ≤ y2 and (x - x2)·(x1 - x2) ≥ 0

<image> The pictures showing two different corners 

In order to test the spell, the wizards will apply it to all the cities that lie on the x-coordinate in the interval [L, R]. After the construction of roads the national government wants to choose the maximum number of pairs of cities connected by the road, so that no city occurs in two or more pairs. Your task is for each m offered variants of values L, R to calculate the maximum number of such pairs after the construction of the roads. Please note that the cities that do not lie in the interval [L, R] on the x-coordinate, do not affect the construction of roads in any way.

Input

The first line contains two space-separated integers n, k (1 ≤ k ≤ n ≤ 105, k ≤ 30). Next k lines contain coordinates of the cities' location points from the first to the k-th one. The j-th line contains space-separated pair of integers xj, yj (0 ≤ xj, yj < 109 + 9) — coordinates of the j-th city.

The next line contains space-separated integers a, b, c, d (2 ≤ a, b, c, d < 109 + 9). It is guaranteed that those numbers are prime and also that a ≠ c, b ≠ d. 

It's guaranteed, that for every two different cities i and j, xi ≠ xj and yi ≠ yj holds.

The next line contains integer m (1 ≤ m ≤ 105) — the number of variants to build the roads. Next m lines contain pairs of space-separated integers Li, Ri (0 ≤ Li ≤ Ri < 109 + 9) — the variants of choosing the cities to build the roads.

Output

For any pair of numbers Li, Ri print the answer to the problem on a single line. Print the answers for the pairs in the order, in which the pairs are given in the input data.

Examples

Input

6 6
0 0
1 1
2 2
3 3
4 4
5 5
2 3 3 2
4
0 5
1 4
2 3
3 3


Output

3
2
1
0


Input

6 1
0 0
3 5 23917 11
4
0 1000000008
0 10
100 150
200 10000


Output

2
1
0
1

Note

In the first sample the roads connect the cities in a chain in the order of increasing of x. 

In the second sample the remaining 5 cities will be located at points (5, 11); (20, 263098); (65, 292514823); (200, 76958738); (605, 622120197).
#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
  friend bool operator<(const node &a, const node &b) { return a.y > b.y; }
} a[100010];
int lc[100010], rc[100010];
int lx[100010], rx[100010];
int x[100010], xn, fr[100010];
int tree[100010 << 2];
int n, m;
int cmp(int x, int y) { return a[x].y > a[y].y ? x : y; }
void init_tree(int p, int tl, int tr) {
  if (tl == tr) {
    tree[p] = fr[tl];
    return;
  }
  int m = (tl + tr) >> 1;
  init_tree(p << 1, tl, m);
  init_tree((p << 1) + 1, m + 1, tr);
  tree[p] = cmp(tree[p << 1], tree[(p << 1) + 1]);
}
int Find(int p, int tl, int tr, int l, int r) {
  if (tl == l && tr == r) return tree[p];
  int m = (tl + tr) >> 1;
  if (l <= m) {
    if (r > m) {
      return cmp(Find(p << 1, tl, m, l, m),
                 Find((p << 1) + 1, m + 1, tr, m + 1, r));
    } else
      return Find(p << 1, tl, m, l, r);
  } else
    return Find((p << 1) + 1, m + 1, tr, l, r);
}
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &a[i].x, &a[i].y);
  long long A, B, C, D;
  int ta, tb, tc, td;
  scanf("%d%d%d%d", &ta, &tb, &tc, &td);
  A = ta, B = tb, C = tc, D = td;
  for (int i = m; i < n; i++) {
    long long tx = (A * a[i - 1].x + B) % 1000000009;
    long long ty = (C * a[i - 1].y + D) % 1000000009;
    a[i].x = (int)tx;
    a[i].y = (int)ty;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) x[i] = a[i].x;
  sort(x, x + n);
  xn = n;
  for (int i = 0; i < n; i++) {
    int k = lower_bound(x, x + n, a[i].x) - x;
    fr[k] = i;
  }
  init_tree(1, 0, n - 1);
}
pair<int, int> q[100010];
int num[100010];
void build() {
  int qn = 1;
  q[0] = make_pair(0, xn - 1);
  num[0] = tree[1];
  for (int p = 0; p < qn; p++) {
    int L = q[p].first, R = q[p].second;
    int d = num[p];
    int k = lower_bound(x, x + n, a[d].x) - x;
    lx[d] = x[L];
    rx[d] = x[R];
    if (k == L)
      lc[d] = -1;
    else {
      lc[d] = Find(1, 0, xn - 1, L, k - 1);
      num[qn] = lc[d];
      q[qn++] = make_pair(L, k - 1);
    }
    if (k == R)
      rc[d] = -1;
    else {
      rc[d] = Find(1, 0, xn - 1, k + 1, R);
      num[qn] = rc[d];
      q[qn++] = make_pair(k + 1, R);
    }
  }
}
struct Tnode {
  int f, g;
  friend Tnode operator+(const Tnode &a, const Tnode &b) {
    Tnode ret;
    ret.g = 0;
    if (a.f > -1) ret.g += a.f;
    if (b.f > -1) ret.g += b.f;
    ret.f = ret.g;
    if (a.f > -1)
      if (b.f > -1)
        ret.f = max(ret.f, a.g + 1 + b.f);
      else
        ret.f = max(ret.f, a.g + 1);
    if (b.f > -1)
      if (a.f > -1)
        ret.f = max(ret.f, b.g + 1 + a.f);
      else
        ret.f = max(ret.f, b.g + 1);
    return ret;
  }
} zero, f[100010];
int root;
void dp(int x) {
  if (lc[x] == -1 && rc[x] == -1) {
    f[x].f = f[x].g = 0;
    return;
  }
  if (lc[x] > -1) dp(lc[x]);
  if (rc[x] > -1) dp(rc[x]);
  Tnode lt = (lc[x] == -1 ? zero : f[lc[x]]);
  Tnode rt = (rc[x] == -1 ? zero : f[rc[x]]);
  f[x] = lt + rt;
}
Tnode get(int p, int L, int R) {
  if (p == -1) return zero;
  if (lx[p] >= L && rx[p] <= R) return f[p];
  if (lx[p] > R || rx[p] < L) return zero;
  int dx = a[p].x;
  if (dx < L) return get(rc[p], L, R);
  if (dx > R) return get(lc[p], L, R);
  Tnode ret = get(lc[p], L, R) + get(rc[p], L, R);
  return ret;
}
void work() {
  int qn;
  for (scanf("%d", &qn); qn; qn--) {
    int L, R;
    scanf("%d%d", &L, &R);
    Tnode ans = get(root, L, R);
    printf("%d\n", max(0, ans.f));
  }
}
int main() {
  init();
  build();
  zero.f = zero.g = -1;
  root = tree[1];
  dp(root);
  work();
  return 0;
}
