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>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG = 20;
inline void fix(int &x) {
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
struct Segment {
  int seg[MAXN << 2], lazy1[MAXN << 2], cnt[MAXN << 2];
  bool lazy2[MAXN << 2];
  void Build(int id, int tl, int tr) {
    lazy1[id] = lazy2[id] = 0;
    if (tr - tl == 1) {
      cnt[id] = 1;
      seg[id] = 0;
      return;
    }
    int mid = (tl + tr) >> 1;
    Build(id << 1, tl, mid);
    Build(id << 1 | 1, mid, tr);
    cnt[id] = cnt[id << 1] + cnt[id << 1 | 1];
    seg[id] = seg[id << 1] + seg[id << 1 | 1];
  }
  void add_lazy1(int id, int val) {
    if (id >= 4 * MAXN) return;
    if (lazy2[id]) shift(id);
    fix(lazy1[id] += val);
    seg[id] = (seg[id] + 1ll * cnt[id] * val) % mod;
  }
  void add_lazy2(int id) {
    if (id >= 4 * MAXN) return;
    lazy2[id] = 1;
    lazy1[id] = 0;
    seg[id] = 0;
  }
  void shift(int id) {
    if (lazy2[id]) {
      lazy2[id] = 0;
      add_lazy2(id << 1);
      add_lazy2(id << 1 | 1);
    }
    if (lazy1[id]) {
      add_lazy1(id << 1, lazy1[id]);
      add_lazy1(id << 1 | 1, lazy1[id]);
      lazy1[id] = 0;
    }
  }
  void Add(int id, int tl, int tr, int l, int r, int val) {
    if (r <= tl || tr <= l) return;
    if (l <= tl && tr <= r) {
      add_lazy1(id, val);
      return;
    }
    shift(id);
    int mid = (tl + tr) >> 1;
    Add(id << 1, tl, mid, l, r, val);
    Add(id << 1 | 1, mid, tr, l, r, val);
    fix(seg[id] = seg[id << 1] + seg[id << 1 | 1]);
  }
  void Set0(int id, int tl, int tr, int l, int r) {
    if (r <= tl || tr <= l) return;
    if (l <= tl && tr <= r) {
      add_lazy2(id);
      return;
    }
    shift(id);
    int mid = (tl + tr) >> 1;
    Set0(id << 1, tl, mid, l, r);
    Set0(id << 1 | 1, mid, tr, l, r);
    cnt[id] = cnt[id << 1] + cnt[id << 1 | 1];
    fix(seg[id] = seg[id << 1] + seg[id << 1 | 1]);
  }
  void SetDead(int id, int tl, int tr, int pos, int typ) {
    if (pos < tl || tr <= pos) return;
    if (tr - tl == 1) {
      cnt[id] = typ;
      seg[id] *= typ;
      return;
    }
    shift(id);
    int mid = (tl + tr) >> 1;
    Set0(id << 1, tl, mid, pos, typ);
    Set0(id << 1 | 1, mid, tr, pos, typ);
    fix(seg[id] = seg[id << 1] + seg[id << 1 | 1]);
  }
  int Get(int id, int tl, int tr, int pos) {
    if (pos < tl || tr <= pos) return 0;
    if (tr - tl == 1) return seg[id];
    shift(id);
    int mid = (tl + tr) >> 1;
    return Get(id << 1, tl, mid, pos) + Get(id << 1 | 1, mid, tr, pos);
  }
} seg;
int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];
vector<int> bad[MAXN], v1[MAXN];
vector<pair<int, int> > v0[MAXN];
set<int> st;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  while (k--) {
    cin >> x >> y >> a >> b;
    bad[y].push_back(a + 1);
    bad[b + 1].push_back(x);
    v0[y].push_back({x, a + 1});
    v1[b + 1].push_back(x);
  }
  seg.Build(1, 0, MAXN);
  seg.Add(1, 0, MAXN, 1, n + 1, 1);
  for (pair<int, int> p : v0[1]) {
    seg.Set0(1, 0, MAXN, p.first, n + 1);
    seg.SetDead(1, 0, MAXN, p.first, 0);
    st.insert(p.first);
  }
  st.insert(n + 1);
  for (int i = 2; i <= m; i++) {
    for (int x : v1[i]) seg.SetDead(1, 0, MAXN, x, 1), st.erase(x);
    for (pair<int, int> p : v0[i]) st.insert(p.first);
    sort(bad[i].begin(), bad[i].end());
    reverse(bad[i].begin(), bad[i].end());
    bad[i].resize(unique(bad[i].begin(), bad[i].end()) - bad[i].begin());
    for (int x : bad[i]) {
      int delta = seg.Get(1, 0, MAXN, x - 1);
      seg.Add(1, 0, MAXN, x, *st.lower_bound(x), delta);
    }
    sort(v0[i].begin(), v0[i].end());
    for (pair<int, int> p : v0[i]) {
      int delta = -seg.Get(1, 0, MAXN, p.second - 1);
      seg.Add(1, 0, MAXN, p.second, *st.lower_bound(p.second), delta);
      seg.Set0(1, 0, MAXN, p.first, p.second);
      seg.SetDead(1, 0, MAXN, p.first, 0);
    }
  }
  fix(ans = seg.Get(1, 0, MAXN, n));
  cout << ans << '\n';
  return 0;
}