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;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ '0');
    ch = getchar();
  }
  return x * f;
}
namespace SegmentTree {
struct node {
  int l, r;
  int val;
  bool tag;
} tree[1000005 << 2];
inline void pushup(const int &i) {
  tree[i].val = (tree[i << 1].val + tree[i << 1 | 1].val) % 1000000007;
}
inline void Change(const int &i, const int &rt) {
  tree[i].val = 0;
  tree[i].tag = true;
}
inline void pushdown(const int &i) {
  if (tree[i].tag) {
    Change(i << 1, i), Change(i << 1 | 1, i);
    tree[i].tag = false;
  }
}
void Build(int l, int r, int i) {
  tree[i].l = l, tree[i].r = r;
  tree[i].tag = 0, tree[i].val = 0;
  if (l == r) {
    return;
  }
  int mid = (l + r) >> 1;
  Build(l, mid, i << 1);
  Build(mid + 1, r, i << 1 | 1);
}
void Cover(int i, int L, int R) {
  if (L <= tree[i].l && tree[i].r <= R) {
    tree[i].tag = true;
    tree[i].val = 0;
    return;
  }
  pushdown(i);
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (L <= mid) Cover(i << 1, L, R);
  if (mid < R) Cover(i << 1 | 1, L, R);
  pushup(i);
}
void Update(int i, int index, int val) {
  if (tree[i].l == tree[i].r) {
    tree[i].val = val;
    return;
  }
  pushdown(i);
  int mid = (tree[i].l + tree[i].r) >> 1;
  if (index <= mid)
    Update(i << 1, index, val);
  else
    Update(i << 1 | 1, index, val);
  pushup(i);
}
int Query(int i, int L, int R) {
  if (L > R) return 0;
  if (L <= tree[i].l && tree[i].r <= R) {
    return tree[i].val;
  }
  pushdown(i);
  int mid = (tree[i].l + tree[i].r) >> 1, ans = 0;
  if (L <= mid) ans = (ans + Query(i << 1, L, R)) % 1000000007;
  if (mid < R) ans = (ans + Query(i << 1 | 1, L, R)) % 1000000007;
  return ans;
}
}  // namespace SegmentTree
using namespace SegmentTree;
struct sgmt {
  int x, y1, y2;
  bool flag;
};
inline bool operator<(const sgmt &A, const sgmt &B) {
  if (A.x != B.x) {
    return A.x < B.x;
  } else {
    if (A.y1 == B.y1) {
      return A.y2 > B.y2;
    } else {
      return A.y1 > B.y1;
    }
  }
}
set<pair<int, int> > now;
sgmt s[1000005 * 2];
int tot;
inline void Add(sgmt A) { s[++tot] = A; }
int main() {
  int n = read(), m = read(), k = read();
  for (register int i = 1; i <= k; ++i) {
    int x1 = read(), y1 = read(), x2 = read(), y2 = read();
    Add(sgmt{x1, y1, y2, 0});
    Add(sgmt{x2 + 1, y1, y2, 1});
  }
  Build(1, m, 1);
  Update(1, 1, 1);
  sort(s + 1, s + 1 + tot);
  int p = 1;
  for (p = 1; s[p].x == 1; ++p) {
    if (s[p].flag == 0) {
      now.insert(make_pair(s[p].y1, s[p].y2));
    }
  }
  now.insert(make_pair(0, 0));
  for (register int i = 2; i <= n; ++i) {
    for (register int j = p; s[j].x == i; ++j) {
      int pos = s[j].y2 + 1;
      if (s[j].flag == 0 && pos <= m) {
        int low = (*--now.lower_bound(make_pair(pos + 1, 0))).second;
        Update(1, pos, Query(1, low + 1, pos));
      }
    }
    for (register int j = p; s[j].x == i; ++j) {
      if (s[j].flag) {
        now.erase(make_pair(s[j].y1, s[j].y2));
      }
    }
    for (register int j = p; s[j].x == i; ++j, ++p) {
      if (!s[j].flag) {
        now.insert(make_pair(s[j].y1, s[j].y2));
        Cover(1, s[j].y1, s[j].y2);
      }
    }
  }
  cout << Query(1, (*(--now.end())).first + 1, m) % 1000000007 << endl;
}