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;
vector<int> tree, flag, tree1;
const int mod = 1e9 + 7;
void rev(int &a) {
  if (a >= mod) {
    a -= mod;
  }
}
void push(int v) {
  if (flag[v]) {
    tree[v * 2] = tree[v * 2 + 1] = 0;
    flag[v * 2] = flag[v * 2 + 1] = 1;
    flag[v] = 0;
  }
}
void update(int v, int l, int r, int ind, int val) {
  if (l == r) {
    tree[v] = val;
    return;
  }
  push(v);
  if (ind <= (r + l) / 2) {
    update(v * 2, l, (r + l) / 2, ind, val);
  } else {
    update(v * 2 + 1, (r + l) / 2 + 1, r, ind, val);
  }
  tree[v] = tree[v * 2] + tree[v * 2 + 1];
  rev(tree[v]);
}
void update1(int v, int l, int r, int al, int ar) {
  if (l >= al && r <= ar) {
    flag[v] = 1;
    tree[v] = 0;
  } else if (l <= ar && r >= al) {
    push(v);
    update1(v * 2, l, (r + l) / 2, al, ar);
    update1(v * 2 + 1, (r + l) / 2 + 1, r, al, ar);
    tree[v] = tree[v * 2] + tree[v * 2 + 1];
    rev(tree[v]);
  }
}
int ans(int v, int l, int r, int al, int ar) {
  if (l >= al && r <= ar) {
    return tree[v];
  } else if (l <= ar && r >= al) {
    push(v);
    int sum = ans(v * 2, l, (r + l) / 2, al, ar) +
              ans(v * 2 + 1, (r + l) / 2 + 1, r, al, ar);
    rev(sum);
    return sum;
  }
  return 0;
}
void update2(int v, int l, int r, int al, int ar) {
  if (l >= al && r <= ar) {
    tree1[v] ^= 1;
  } else if (l <= ar && r >= al) {
    update2(v * 2, l, (r + l) / 2, al, ar);
    update2(v * 2 + 1, (r + l) / 2 + 1, r, al, ar);
  }
}
int ans2(int v, int l, int r, int id) {
  if (l == r) {
    return tree1[v];
  }
  if (id <= (r + l) / 2) {
    return tree1[v] ^ ans2(v * 2, l, (r + l) / 2, id);
  } else {
    return tree1[v] ^ ans2(v * 2 + 1, (r + l) / 2 + 1, r, id);
  }
}
signed main() {
  int n, m, k;
  cin >> n >> m >> k;
  tree.resize(4 * m);
  flag.resize(4 * m);
  tree1.resize(4 * m);
  set<pair<int, int> > s;
  vector<pair<pair<int, int>, pair<int, int> > > mass(k);
  vector<pair<pair<int, int>, int> > scan;
  for (int i = 0; i < k; i++) {
    cin >> mass[i].first.first >> mass[i].second.first >>
        mass[i].first.second >> mass[i].second.second;
    scan.push_back({{mass[i].first.first, -1}, i});
    scan.push_back({{mass[i].first.second + 1, 2}, i});
  }
  update(1, 0, m - 1, 0, 1);
  sort(scan.begin(), scan.end());
  for (int i = 0; i < scan.size(); i++) {
    int ind = scan[i].second;
    int type = scan[i].first.second;
    if (type == 2) {
      if (scan[i].first.first == n + 1) {
        break;
      }
      s.erase({mass[ind].second.second - 1, ind});
      update2(1, 0, m - 1, mass[ind].second.first - 1,
              mass[ind].second.second - 1);
    } else {
      int y1 = mass[ind].second.first;
      int y2 = mass[ind].second.second;
      y1--;
      y2--;
      if (mass[ind].first.first != 1 && y2 != m - 1 &&
          ans2(1, 0, m - 1, y2 + 1) == 0) {
        set<pair<int, int> >::iterator it;
        it = s.lower_bound({y2 + 1, 0});
        if (s.size() == 0 || it == s.begin()) {
          int sum = ans(1, 0, m - 1, 0, y2 + 1);
          update(1, 0, m - 1, y2 + 1, sum);
        } else {
          it--;
          int sum = ans(1, 0, m - 1, it->first + 1, y2 + 1);
          update(1, 0, m - 1, y2 + 1, sum);
        }
      }
      s.insert({y2, ind});
      update2(1, 0, m - 1, y1, y2);
      update1(1, 0, m - 1, y1, y2);
    }
  }
  if (s.size() == 0) {
    cout << ans(1, 0, m - 1, 0, m - 1);
  } else if (s.rbegin()->first == m - 1) {
    cout << 0;
  } else {
    cout << ans(1, 0, m - 1, s.rbegin()->first + 1, m - 1);
  }
  return 0;
}