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>
using namespace std;
int IN() {
  int x = 0, f = 0, ch;
  for (; (ch = getchar()) < '0' || ch > '9';) f = (ch == '-');
  for (; ch >= '0' && ch <= '9'; (ch = getchar())) x = x * 10 + ch - '0';
  return f ? -x : x;
}
int N, M, K;
vector<pair<int, int> > G1[1000005], G2[1000005], G3[1000005];
struct Nod {
  int sum, laz, Max, Cov;
} T[1000005 << 2];
void Clear(int u) {
  T[u].sum = 0;
  T[u].laz = 1;
}
void Cov(int u, int c) { T[u].Cov = T[u].Max = c; }
void Up(int u) {
  T[u].sum = (T[u << 1].sum + T[u << 1 | 1].sum) % 1000000007;
  T[u].Max = max(T[u << 1].Max, T[u << 1 | 1].Max);
}
void Down(int u) {
  if (T[u].laz) {
    Clear(u << 1);
    Clear(u << 1 | 1);
    T[u].laz = 0;
  }
  if (T[u].Cov != -1) {
    Cov(u << 1, T[u].Cov);
    Cov(u << 1 | 1, T[u].Cov);
    T[u].Cov = -1;
  }
}
void Build(int u, int l, int r) {
  T[u].Cov = -1;
  if (l == r) return;
  int Mid = (l + r) >> 1;
  Build(u << 1, l, Mid);
  Build(u << 1, Mid + 1, r);
}
void ModifyVal(int u, int l, int r, int x, int v) {
  if (l == r) {
    T[u].sum = v;
    return;
  }
  int Mid = (l + r) >> 1;
  Down(u);
  if (x <= Mid)
    ModifyVal(u << 1, l, Mid, x, v);
  else
    ModifyVal(u << 1 | 1, Mid + 1, r, x, v);
  Up(u);
}
void ModifyCov(int u, int l, int r, int x, int y, int v) {
  if (x <= l && r <= y) {
    Cov(u, v);
    return;
  }
  int Mid = (l + r) >> 1;
  Down(u);
  if (x <= Mid) ModifyCov(u << 1, l, Mid, x, y, v);
  if (y > Mid) ModifyCov(u << 1 | 1, Mid + 1, r, x, y, v);
  Up(u);
}
void ModifySum(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    Clear(u);
    return;
  }
  int Mid = (l + r) >> 1;
  Down(u);
  if (x <= Mid) ModifySum(u << 1, l, Mid, x, y);
  if (y > Mid) ModifySum(u << 1 | 1, Mid + 1, r, x, y);
  Up(u);
}
int QueryMax(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) return T[u].Max;
  int Mid = (l + r) >> 1;
  Down(u);
  if (y <= Mid) return QueryMax(u << 1, l, Mid, x, y);
  if (x > Mid) return QueryMax(u << 1 | 1, Mid + 1, r, x, y);
  return max(QueryMax(u << 1, l, Mid, x, y),
             QueryMax(u << 1 | 1, Mid + 1, r, x, y));
}
int QuerySum(int u, int l, int r, int x, int y) {
  if (x <= l && r <= y) return T[u].sum;
  int Mid = (l + r) >> 1;
  Down(u);
  if (y <= Mid) return QuerySum(u << 1, l, Mid, x, y);
  if (x > Mid) return QuerySum(u << 1 | 1, Mid + 1, r, x, y);
  return (QuerySum(u << 1, l, Mid, x, y) +
          QuerySum(u << 1 | 1, Mid + 1, r, x, y)) %
         1000000007;
}
int main(int argc, char* argv[]) {
  N = IN();
  M = IN();
  K = IN();
  for (int i = 1, lim = K; i <= lim; i++) {
    int x1 = IN(), y1 = IN(), x2 = IN(), y2 = IN();
    G1[x1].push_back(make_pair(y1, y2));
    G2[x2 + 1].push_back(make_pair(y1, y2));
    G3[x1].push_back(make_pair(y2 + 1, 0));
  }
  G3[N + 1].push_back(make_pair(M, 0));
  Build(1, 1, M);
  ModifyVal(1, 1, M, 1, 1);
  ModifyCov(1, 1, M, 2, M, M);
  for (int i = 1, lim = N + 1; i <= lim; i++) {
    for (int j = 1, lim = G3[i].size(); j <= lim; j++) {
      int x = G3[i][j - 1].first, y = QueryMax(1, 1, M, 1, x);
      if (y + 1 <= x) G3[i][j - 1].second = QuerySum(1, 1, M, y + 1, x);
    }
    for (int j = 1, lim = G2[i].size(); j <= lim; j++)
      ModifyCov(1, 1, M, G2[i][j - 1].first, G2[i][j - 1].second, 0);
    if (i == 1) ModifyCov(1, 1, M, 2, M, 0);
    for (int j = 1, lim = G3[i].size(); j <= lim; j++)
      ModifyVal(1, 1, M, G3[i][j - 1].first, G3[i][j - 1].second);
    for (int j = 1, lim = G1[i].size(); j <= lim; j++) {
      ModifyCov(1, 1, M, G1[i][j - 1].first, G1[i][j - 1].second,
                G1[i][j - 1].second);
      ModifySum(1, 1, M, G1[i][j - 1].first, G1[i][j - 1].second);
    }
  }
  printf("%d\n", G3[N + 1][0].second);
  return 0;
}