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;
const int maxn = 1e6 + 10;
const int BASE = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct SegmentTree {
  int st[6 * maxn], lp[6 * maxn];
  int L[6 * maxn], R[6 * maxn];
  void Build(int k, int x, int y) {
    L[k] = x;
    R[k] = y;
    st[k] = 0;
    lp[k] = -1;
    if (L[k] == R[k]) return;
    Build(k << 1, L[k], ((L[k] + R[k]) >> 1));
    Build(k << 1 | 1, ((L[k] + R[k]) >> 1) + 1, R[k]);
  }
  void Propagate(int k) {
    if (lp[k] == -1) return;
    int v = lp[k];
    lp[k] = -1;
    lp[k << 1] = lp[k << 1 | 1] = v;
    st[k << 1] = (long long)(R[k << 1] - L[k << 1] + 1) * (long long)v % BASE;
    st[k << 1 | 1] =
        (long long)(R[k << 1 | 1] - L[k << 1 | 1] + 1) * (long long)v % BASE;
  }
  void Update(int k, int i, int j, int v) {
    if (L[k] > j || R[k] < i) return;
    if (i <= L[k] && R[k] <= j) {
      st[k] = (long long)(R[k] - L[k] + 1) * (long long)v % BASE;
      lp[k] = v;
      return;
    }
    Propagate(k);
    Update(k << 1, i, j, v);
    Update(k << 1 | 1, i, j, v);
    st[k] = (st[k << 1] + st[k << 1 | 1]) % BASE;
  }
  int Query(int k, int i, int j) {
    int res = 0;
    if (L[k] > j || R[k] < i) return 0;
    if (i <= L[k] && R[k] <= j) return st[k];
    Propagate(k);
    res += Query(k << 1, i, j) + Query(k << 1 | 1, i, j);
    res %= BASE;
    st[k] = (st[k << 1] + st[k << 1 | 1]) % BASE;
    return res;
  }
} Tree;
vector<pair<int, int> > In[maxn], Out[maxn];
int n, m, k;
int a[maxn], b[maxn], N;
set<pair<int, int> > S;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; ++i) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    In[x1].push_back(pair<int, int>(y1, y2));
    Out[x2 + 1].push_back(pair<int, int>(y1, y2));
  }
  Tree.Build(1, 1, m);
  Tree.Update(1, 1, 1, 1);
  for (int k = 0; k < In[1].size(); ++k) S.insert(In[1][k]);
  for (int i = 2; i <= n; ++i) {
    N = 0;
    for (int k = 0; k < In[i].size(); ++k) {
      pair<int, int> T = In[i][k];
      if (T.second + 1 > m) continue;
      set<pair<int, int> >::iterator it =
          S.upper_bound(pair<int, int>(T.second + 1, INF));
      int Low = 0, High = T.second + 1;
      if (it != S.begin()) {
        --it;
        Low = it->second;
      }
      a[++N] = (Low + 1 > High) ? 0 : Tree.Query(1, Low + 1, High);
      b[N] = High;
    }
    for (int k = 1; k <= N; ++k) Tree.Update(1, b[k], b[k], a[k]);
    for (int k = 0; k < Out[i].size(); ++k) S.erase(Out[i][k]);
    for (int k = 0; k < In[i].size(); ++k) {
      Tree.Update(1, In[i][k].first, In[i][k].second, 0);
      S.insert(In[i][k]);
    }
  }
  int Low = (S.empty()) ? 0 : (--S.end())->second;
  int ans = Tree.Query(1, Low + 1, m);
  printf("%d", ans);
  return 0;
}