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 mo = 1e9 + 7;
const int N = 1e6 + 500;
void ntr(int &x) { x = x >= mo ? x - mo : (x < 0 ? x + mo : x); }
void inc(int &x, int y) { x += y, ntr(x); }
struct node {
  int x, l, r, f;
} a[200050];
bool cmp(node a, node b) {
  if (a.x == b.x)
    if (a.f == b.f)
      return a.l > b.l;
    else
      return a.f < b.f;
  else
    return a.x < b.x;
}
int n, m, K, tot, sum[N << 2], mx[N << 2], tgb[N << 2], flg;
bool tg[N << 2];
void build(int x, int l, int r) {
  if (l == r) {
    sum[x] = (l == 1);
    return;
  }
  int mi = (l + r) >> 1;
  build(x << 1, l, mi);
  build(x << 1 | 1, mi + 1, r);
  sum[x] = sum[x << 1] + sum[x << 1 | 1], ntr(sum[x]);
}
void up(int x) {
  sum[x] = sum[x << 1] + sum[x << 1 | 1], ntr(sum[x]);
  mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}
void pd1(int x) { sum[x] = 0, tg[x] = 1; }
void pd2(int x, int y) { mx[x] += y, tgb[x] += y; }
void pd(int x) {
  if (tg[x]) pd1(x << 1), pd1(x << 1 | 1), tg[x] = 0;
  if (tgb[x] != 0) pd2(x << 1, tgb[x]), pd2(x << 1 | 1, tgb[x]), tgb[x] = 0;
}
int askb(int x, int l, int r, int pos) {
  if (l == r) return mx[x];
  int mi = (l + r) >> 1, ans;
  pd(x);
  if (pos <= mi)
    ans = askb(x << 1, l, mi, pos);
  else
    ans = askb(x << 1 | 1, mi + 1, r, pos);
  return ans;
}
int askdp(int x, int l, int r, int pos) {
  if (l == r) return sum[x];
  int mi = (l + r) >> 1, ans;
  pd(x);
  if (pos <= mi)
    ans = askdp(x << 1, l, mi, pos);
  else
    ans = askdp(x << 1 | 1, mi + 1, r, pos);
  return ans;
}
void clrdp(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    sum[x] = 0;
    tg[x] = 1;
    mx[x]++;
    tgb[x]++;
    return;
  }
  int mi = (l + r) >> 1;
  pd(x);
  if (L <= mi) clrdp(x << 1, l, mi, L, R);
  if (mi < R) clrdp(x << 1 | 1, mi + 1, r, L, R);
  up(x);
}
void delb(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    mx[x]--, tgb[x]--;
    return;
  }
  int mi = (l + r) >> 1;
  pd(x);
  if (L <= mi) delb(x << 1, l, mi, L, R);
  if (mi < R) delb(x << 1 | 1, mi + 1, r, L, R);
  up(x);
}
int play(int x, int l, int r, int R) {
  if (r <= R && mx[x] == 0) {
    flg = 1;
    return sum[x];
  }
  if (l == r) {
    flg = 0;
    return 0;
  }
  int mi = (l + r) >> 1, ans = 0;
  pd(x);
  if (mi + 1 <= R) {
    inc(ans, play(x << 1 | 1, mi + 1, r, R));
    if (flg) inc(ans, play(x << 1, l, mi, R));
  } else
    ans = play(x << 1, l, mi, R);
  return ans;
}
void modify(int x, int l, int r, int pos, int dt) {
  inc(sum[x], dt);
  if (l == r) return;
  int mi = (l + r) >> 1;
  pd(x);
  if (pos <= mi)
    modify(x << 1, l, mi, pos, dt);
  else
    modify(x << 1 | 1, mi + 1, r, pos, dt);
}
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);
    a[++tot].x = x1, a[tot].l = y1, a[tot].r = y2, a[tot].f = 0;
    a[++tot].x = x2 + 1, a[tot].l = y1, a[tot].r = y2, a[tot].f = 1;
  }
  sort(a + 1, a + tot + 1, cmp);
  build(1, 1, m);
  for (int i = 1; i <= tot; i++) {
    if (a[i].x > n) continue;
    if (!a[i].f) {
      if (!(a[i].x == 1 || a[i].r == m || askb(1, 1, m, a[i].r + 1) > 0)) {
        int t = play(1, 1, m, a[i].r);
        modify(1, 1, m, a[i].r + 1, t);
      }
      clrdp(1, 1, m, a[i].l, a[i].r);
    } else
      delb(1, 1, m, a[i].l, a[i].r);
  }
  int ans = play(1, 1, m, m);
  printf("%d\n", ans);
  return 0;
}