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 n, m, K, tot;
struct node {
  int type;
  int x, y1, y2;
} b[1000005];
bool cmp(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.y1 != b.y1) return a.y1 > b.y1;
  return a.y2 > b.y2;
}
set<pair<int, int> > s;
int a[1000005 * 4], flag[1000005 * 4];
void down(int x, int l, int r) {
  if (flag[x] != -1) {
    int mid = (l + r) / 2;
    a[x * 2] = 1ll * (mid - l + 1) * flag[x] % 1000000007;
    flag[x * 2] = flag[x];
    a[x * 2 + 1] = 1ll * (r - mid) * flag[x] % 1000000007;
    flag[x * 2 + 1] = flag[x];
    flag[x] = -1;
  }
}
void cover(int x, int l, int r, int tx, int ty, int val) {
  if (tx > ty) return;
  if (l >= tx && r <= ty) {
    a[x] = 1ll * val * (r - l + 1) % 1000000007;
    flag[x] = val;
    return;
  }
  down(x, l, r);
  int mid = (l + r) / 2;
  if (mid >= tx) cover(x * 2, l, mid, tx, ty, val);
  if (mid < ty) cover(x * 2 + 1, mid + 1, r, tx, ty, val);
  a[x] = (a[x * 2] + a[x * 2 + 1]) % 1000000007;
}
int query(int x, int l, int r, int tx, int ty) {
  if (tx > ty) return 0;
  if (l >= tx && r <= ty) return a[x];
  down(x, l, r);
  int mid = (l + r) / 2, ret = 0;
  if (mid >= tx) ret += query(x * 2, l, mid, tx, ty);
  if (mid < ty) ret = (ret + query(x * 2 + 1, mid + 1, r, tx, ty)) % 1000000007;
  return ret;
}
void build(int x, int l, int r) {
  flag[x] = -1;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
}
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);
    b[++tot].type = 1;
    b[tot].x = x1;
    b[tot].y1 = y1;
    b[tot].y2 = y2;
    b[++tot].type = 0;
    b[tot].x = x2 + 1;
    b[tot].y1 = y1;
    b[tot].y2 = y2;
  }
  build(1, 1, m);
  sort(b + 1, b + tot + 1, cmp);
  cover(1, 1, m, 1, 1, 1);
  int wh = 1;
  for (; wh <= tot && b[wh].x == 1; wh++)
    s.insert(make_pair(b[wh].y1, b[wh].y2));
  s.insert(make_pair(0, 0));
  for (int i = 2; i <= n; i++) {
    for (int j = wh; j <= tot && b[j].x == i; j++) {
      if (b[j].type == 1 && b[j].y2 < m) {
        pair<int, int> t = *(--s.lower_bound(make_pair(b[j].y2 + 2, 0)));
        int tmp = query(1, 1, m, t.second + 1, b[j].y2 + 1);
        cover(1, 1, m, b[j].y2 + 1, b[j].y2 + 1, tmp);
      }
    }
    for (int j = wh; j <= tot && b[j].x == i; j++) {
      if (b[j].type == 0) {
        s.erase(make_pair(b[j].y1, b[j].y2));
      }
    }
    for (; wh <= tot && b[wh].x == i; wh++) {
      if (b[wh].type == 1) {
        s.insert(make_pair(b[wh].y1, b[wh].y2));
        cover(1, 1, m, b[wh].y1, b[wh].y2, 0);
      }
    }
  }
  pair<int, int> t = *(--s.end());
  printf("%d\n", query(1, 1, m, t.first + 1, m));
  return 0;
}