Problem: Little girl Masha likes winter sports, today she's planning to take part in slalom skiing.

The track is represented as a grid composed of n × m squares. There are rectangular obstacles at the track, composed of grid squares. Masha must get from the square (1, 1) to the square (n, m). She can move from a square to adjacent square: either to the right, or upwards. If the square is occupied by an obstacle, it is not allowed to move to that square.

One can see that each obstacle can actually be passed in two ways: either it is to the right of Masha's path, or to the left. Masha likes to try all ways to do things, so she would like to know how many ways are there to pass the track. Two ways are considered different if there is an obstacle such that it is to the right of the path in one way, and to the left of the path in the other way.

Help Masha to find the number of ways to pass the track. The number of ways can be quite big, so Masha would like to know it modulo 109 + 7.

The pictures below show different ways to pass the track in sample tests. <image> <image> <image>

Input

The first line of input data contains three positive integers: n, m and k (3 ≤ n, m ≤ 106, 0 ≤ k ≤ 105) — the size of the track and the number of obstacles.

The following k lines contain four positive integers each: x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ m) — coordinates of bottom left, and top right squares of the obstacle. 

It is guaranteed that there are no obstacles at squares (1, 1) and (n, m), and no obstacles overlap (but some of them may touch).

Output

Output one integer — the number of ways to pass the track modulo 109 + 7.

Examples

Input

3 3 0


Output

1


Input

4 5 1
2 2 3 4


Output

2


Input

5 5 3
2 2 2 3
4 2 5 2
4 4 4 4


Output

3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
const int MOD = 1000000007;
int same[2111111], w[2111111], b[2111111], size[2111111];
inline void inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
void SAME(int p, int d) {
  same[p] = 1;
  w[p] = d;
}
void ADD(int p, int d) { inc(w[p], d); }
void DOWN(int p) {
  if (same[p]) {
    SAME(p << 1, w[p]);
    SAME(p << 1 | 1, w[p]);
    same[p] = w[p] = 0;
  } else if (w[p]) {
    ADD(p << 1, w[p]);
    ADD(p << 1 | 1, w[p]);
    w[p] = 0;
  }
}
void P(int p, int l, int r, int L, int R, int d) {
  if (L <= l && r <= R)
    ADD(p, d);
  else {
    int m = l + r >> 1;
    DOWN(p);
    if (L <= m) P(p << 1, l, m, L, R, d);
    if (R > m) P(p << 1 | 1, m + 1, r, L, R, d);
  }
}
void S(int p, int l, int r, int L, int R, int d) {
  if (L <= l && r <= R)
    SAME(p, d);
  else {
    int m = l + r >> 1;
    DOWN(p);
    if (L <= m) S(p << 1, l, m, L, R, d);
    if (R > m) S(p << 1 | 1, m + 1, r, L, R, d);
  }
}
int G(int p, int l, int r, int x) {
  while (l < r) {
    DOWN(p);
    int m = l + r >> 1;
    if (x <= m)
      p <<= 1, r = m;
    else
      p = p << 1 | 1, l = m + 1;
  }
  return w[p];
}
void BUILD(int p, int l, int r) {
  size[p] = r - l + 1;
  if (l < r) {
    int m = l + r >> 1;
    BUILD(p << 1, l, m);
    BUILD(p << 1 | 1, m + 1, r);
  }
}
void DOWNB(int p) {
  if (b[p] == 0)
    b[p << 1] = b[p << 1 | 1] = 0;
  else if (b[p] == size[p])
    b[p << 1] = size[p << 1], b[p << 1 | 1] = size[p << 1 | 1];
}
void B(int p, int l, int r, int L, int R, int d) {
  if (L <= l && r <= R)
    if (d == 1)
      b[p] = size[p];
    else
      b[p] = 0;
  else {
    int m = l + r >> 1;
    DOWNB(p);
    if (L <= m) B(p << 1, l, m, L, R, d);
    if (R > m) B(p << 1 | 1, m + 1, r, L, R, d);
    b[p] = b[p << 1] + b[p << 1 | 1];
  }
}
int FIRSTB(int p, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    if (!b[p]) return -1;
    while (l < r) {
      int m = l + r >> 1;
      DOWNB(p);
      if (b[p << 1])
        p <<= 1, r = m;
      else
        p = p << 1 | 1, l = m + 1;
    }
    return l;
  } else {
    int m = l + r >> 1;
    DOWNB(p);
    int left = L <= m ? FIRSTB(p << 1, l, m, L, R) : -1;
    return ~left ? left : (R > m ? FIRSTB(p << 1 | 1, m + 1, r, L, R) : -1);
  }
}
int N, M, K, D;
std::vector<std::pair<int, int> > ins[1000002], rmv[1000002];
std::pair<int, int> option[100002];
int main() {
  scanf("%d%d%d", &N, &M, &K);
  for (int i = 1; i <= K; i++) {
    int u, l, d, r;
    scanf("%d%d%d%d", &u, &l, &d, &r);
    ins[u].push_back({l, r});
    rmv[d + 1].push_back({l, r});
  }
  std::sort(ins[1].begin(), ins[1].end());
  BUILD(1, 1, M);
  if (ins[1].empty())
    P(1, 1, M, 1, M, 1);
  else if (ins[1][0].first > 1)
    P(1, 1, M, 1, ins[1][0].first - 1, 1);
  for (auto &i : ins[1]) B(1, 1, M, i.first, i.second, 1);
  for (int i = 2; i <= N; i++) {
    D = 0;
    for (auto &j : rmv[i]) {
      if (j.first > 1) option[D++] = {j.first - 1, G(1, 1, M, j.first - 1)};
      B(1, 1, M, j.first, j.second, 0);
    }
    for (auto &j : ins[i]) {
      B(1, 1, M, j.first, j.second, 1);
      S(1, 1, M, j.first, j.second, 0);
    }
    for (int j = 0; j < D; j++) {
      int fb = FIRSTB(1, 1, M, option[j].first, M);
      if (fb == -1)
        P(1, 1, M, option[j].first + 1, M, option[j].second);
      else if (fb > option[j].first + 1)
        P(1, 1, M, option[j].first + 1, fb - 1, option[j].second);
    }
  }
  printf("%d\n", G(1, 1, M, M));
  return 0;
}