#include <bits/stdc++.h>
using namespace std;
set<int> TR[313131];
void qr(int w, int s, int e, int l, int r, int v, int flag) {
  if (s == l && e == r) {
    if (!flag)
      TR[w].insert(-v);
    else
      TR[w].erase(-v);
    return;
  }
  int m = (s + e) / 2;
  if (l <= m) qr(w * 2, s, m, l, min(m, r), v, flag);
  if (m + 1 <= r) qr(w * 2 + 1, m + 1, e, max(m + 1, l), r, v, flag);
}
int get_max(int w) {
  if (TR[w].size() == 0) return 0;
  return -*TR[w].begin();
}
int get_v(int w, int s, int e, int now) {
  if (s == e) return get_max(w);
  int m = (s + e) / 2;
  if (now <= m)
    return max(get_v(w * 2, s, m, now), get_max(w));
  else
    return max(get_v(w * 2 + 1, m + 1, e, now), get_max(w));
}
struct xy {
  int x, y, cnt;
} P[321212];
int pn, nxt[323232];
struct br {
  int u, l, r, s, p1, p2;
} B[212121];
bool sort_u(br a, br b) { return a.u < b.u; }
vector<pair<int, pair<int, int>>> Q;
int main() {
  int H, W, n, i, j;
  scanf("%d%d%d", &H, &W, &n);
  for (i = 1; i <= n; i++)
    scanf("%d%d%d%d", &B[i].u, &B[i].l, &B[i].r, &B[i].s);
  sort(B + 1, B + n + 1, sort_u);
  for (i = 1; i <= n; i++) {
    int u = B[i].u, l = B[i].l, r = B[i].r, s = B[i].s;
    B[i].p1 = pn, B[i].p2 = pn + 1;
    P[pn++] = {l == 1 ? r + 1 : l - 1, u, 0};
    P[pn++] = {r == W ? l - 1 : r + 1, u, 0};
    Q.push_back({u + 1, {0, i}});
    Q.push_back({u + s + 1, {1, i}});
  }
  for (i = 1; i <= W; i++) P[pn++] = {i, H + 1, 1};
  for (i = 0; i < pn; i++) Q.push_back({P[i].y, {2, i}});
  sort(Q.begin(), Q.end());
  for (auto q : Q) {
    int type = q.second.first, w = q.second.second;
    if (type == 2)
      nxt[w] = get_v(1, 1, W, P[w].x);
    else
      qr(1, 1, W, B[w].l, B[w].r, w, type);
  }
  int ans = 0, mod = 1e9 + 7;
  for (i = pn - 1; i >= 0; i--) {
    if (nxt[i] == 0)
      ans = (ans + P[i].cnt) % mod;
    else {
      int NXT = nxt[i];
      int p1 = B[NXT].p1, p2 = B[NXT].p2;
      P[p1].cnt = (P[p1].cnt + P[i].cnt) % mod;
      P[p2].cnt = (P[p2].cnt + P[i].cnt) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
