#include <bits/stdc++.h>
using namespace std;
int n, m, K, g[200050], lc;
struct A {
  int h, l, r, f;
  A() { h = l = r = f = 0; }
  bool operator<(const A &x) const { return h < x.h; }
} a[200050];
struct B {
  int p, opt, id;
  bool operator<(const B &x) const { return p < x.p; }
} b[200050 << 1];
set<int> S;
struct C {
  int x, y, id, opt, ans;
} c[200050 << 2];
struct D {
  int v, id;
  bool operator<(const D &x) const { return v > x.v; }
} d[200050 << 1], e[200050 << 1];
int mx[200050 << 2];
void update(int l, int r, int x, int y, int v, int p) {
  if (x <= l && y >= r) {
    mx[p] = max(mx[p], v);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) update(l, mid, x, y, v, p << 1);
  if (y > mid) update(mid + 1, r, x, y, v, p << 1 | 1);
}
int query(int l, int r, int x, int p) {
  if (l == r) return mx[p];
  int mid = (l + r) >> 1, re = mx[p];
  if (x <= mid)
    return max(re, query(l, mid, x, p << 1));
  else
    return max(re, query(mid + 1, r, x, p << 1 | 1));
}
void rec(int l, int r, int x, int y, int p) {
  if (x <= l && y >= r) {
    mx[p] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) rec(l, mid, x, y, p << 1);
  if (y > mid) rec(mid + 1, r, x, y, p << 1 | 1);
}
void solve(int l, int r) {
  if (l > r) puts("FUCK");
  if (l == r) {
    if (c[l].opt == 1) {
      g[c[l].id] = (g[c[l].id] + g[c[l].ans]) % 1000000007;
    }
    return;
  }
  int mid = (l + r) >> 1, i, j;
  solve(l, mid);
  int ld = 0, le = 0;
  for (i = l; i <= mid; i++) {
    if (c[i].opt == 0) {
      d[++ld] = (D){a[c[i].id].f + a[c[i].id].h, c[i].id};
    }
  }
  for (i = mid + 1; i <= r; i++) {
    if (c[i].opt == 1) {
      e[++le] = (D){c[i].x, i};
    }
  }
  sort(d + 1, d + ld + 1);
  sort(e + 1, e + le + 1);
  j = 1;
  for (i = 1; i <= le; i++) {
    for (; j <= ld && d[j].v >= e[i].v; j++) {
      int p = d[j].id;
      update(1, m, a[p].l, a[p].r, p, 1);
    }
    c[e[i].id].ans = max(c[e[i].id].ans, query(1, m, c[e[i].id].y, 1));
  }
  for (i = 1; i < j; i++) {
    int p = d[i].id;
    rec(1, m, a[p].l, a[p].r, 1);
  }
  solve(mid + 1, r);
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  if (!K) {
    printf("%d\n", m);
    return 0;
  }
  int i, sum = 0;
  for (i = 1; i <= K; i++) {
    scanf("%d%d%d%d", &a[i].h, &a[i].l, &a[i].r, &a[i].f);
  }
  sort(a + 1, a + K + 1);
  g[0] = 1;
  for (i = 1; i <= K; i++) {
    int x = a[i].h, y, z;
    if (a[i].l == 1)
      y = z = a[i].r + 1;
    else if (a[i].r == m)
      y = z = a[i].l - 1;
    else
      y = a[i].l - 1, z = a[i].r + 1;
    c[++lc] = (C){x, y, i, 1, 0};
    c[++lc] = (C){x, z, i, 1, 0};
    c[++lc] = (C){0, 0, i, 0, 0};
  }
  solve(1, lc);
  int lb = 0;
  for (i = 1; i <= K; i++) {
    if (n + 1 - a[i].h <= a[i].f) {
      b[++lb] = (B){a[i].l, 1, i};
      b[++lb] = (B){a[i].r + 1, -1, i};
    }
  }
  sort(b + 1, b + lb + 1);
  int j = 1;
  for (i = 1; i <= m; i++) {
    for (; j <= lb && b[j].p <= i; j++) {
      if (b[j].opt == 1)
        S.insert(b[j].id);
      else
        S.erase(b[j].id);
    }
    set<int>::iterator it = S.end();
    int tmp;
    if (it == S.begin())
      tmp = 0;
    else {
      it--;
      tmp = *it;
    }
    sum = (sum + g[tmp]) % 1000000007;
  }
  printf("%d\n", sum);
}
