#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int h, w, n, ans[200005];
map<int, int> pos;
struct node {
  int s, h, l, r;
  bool operator<(const node &x) const {
    if (s == x.s) return h > x.h;
    return s < x.s;
  }
};
vector<node> V;
set<int> tree[1000005];
int ls(int p) { return p << 1; }
int rs(int p) { return p << 1 | 1; }
void update(int l, int r, int ll, int rr, int h, int p, bool flag) {
  if (ll <= l && r <= rr) {
    if (flag)
      tree[p].insert(h);
    else
      tree[p].erase(h);
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) update(l, mid, ll, rr, h, ls(p), flag);
  if (rr > mid) update(mid + 1, r, ll, rr, h, rs(p), flag);
}
int query(int l, int r, int ll, int rr, int p) {
  int ans = 0, mid = (l + r) >> 1;
  if (!tree[p].empty()) ans = *tree[p].rbegin();
  if (ll <= l && r <= rr) return ans;
  if (ll <= mid) ans = max(ans, query(l, mid, ll, rr, ls(p)));
  if (rr > mid) ans = max(ans, query(mid + 1, r, ll, rr, rs(p)));
  return ans;
}
int main() {
  cin >> h >> w >> n;
  for (int i = 1; i <= n; i++) {
    int u, l, r, s;
    cin >> u >> l >> r >> s;
    V.push_back((node){u + s, u, l, r});
    V.push_back((node){u, u, l, r});
    pos[u] = i;
  }
  ans[0] = 1;
  sort(V.begin(), V.end());
  for (int i = 0; i < V.size(); i++) {
    if (V[i].s != V[i].h) {
      if (V[i].s > h) break;
      update(1, w, V[i].l, V[i].r, V[i].h, 1, 0);
    } else {
      if (V[i].l == 1) {
        int tmp = query(1, w, V[i].r + 1, V[i].r + 1, 1);
        ans[pos[V[i].h]] = ans[pos[tmp]] * 2 % mod;
      } else if (V[i].r == w) {
        int tmp = query(1, w, V[i].l - 1, V[i].l - 1, 1);
        ans[pos[V[i].h]] = ans[pos[tmp]] * 2 % mod;
      } else {
        int tmp1 = query(1, w, V[i].l - 1, V[i].l - 1, 1);
        int tmp2 = query(1, w, V[i].r + 1, V[i].r + 1, 1);
        ans[pos[V[i].h]] = (ans[pos[tmp1]] + ans[pos[tmp2]]) % mod;
      }
      update(1, w, V[i].l, V[i].r, V[i].h, 1, 1);
    }
  }
  int ANS = 0;
  for (int i = 1; i <= w; i++)
    ANS = (ANS + ans[pos[query(1, w, i, i, 1)]]) % mod;
  cout << ANS;
}
