#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
struct modint {
  int x;
  modint(int o = 0) { x = o; }
  modint &operator=(int o) { return x = o, *this; }
  modint &operator+=(modint o) {
    return x = x + o.x >= 1000000007 ? x + o.x - 1000000007 : x + o.x, *this;
  }
  modint &operator-=(modint o) {
    return x = x - o.x < 0 ? x - o.x + 1000000007 : x - o.x, *this;
  }
  modint &operator*=(modint o) { return x = 1ll * x * o.x % 1000000007, *this; }
  modint &operator^=(int b) {
    modint a = *this, c = 1;
    for (; b; b >>= 1, a *= a)
      if (b & 1) c *= a;
    return x = c.x, *this;
  }
  modint &operator/=(modint o) { return *this *= o ^= 1000000007 - 2; }
  modint &operator+=(int o) {
    return x = x + o >= 1000000007 ? x + o - 1000000007 : x + o, *this;
  }
  modint &operator-=(int o) {
    return x = x - o < 0 ? x - o + 1000000007 : x - o, *this;
  }
  modint &operator*=(int o) { return x = 1ll * x * o % 1000000007, *this; }
  modint &operator/=(int o) { return *this *= ((modint(o)) ^= 1000000007 - 2); }
  template <class I>
  friend modint operator+(modint a, I b) {
    return a += b;
  }
  template <class I>
  friend modint operator-(modint a, I b) {
    return a -= b;
  }
  template <class I>
  friend modint operator*(modint a, I b) {
    return a *= b;
  }
  template <class I>
  friend modint operator/(modint a, I b) {
    return a /= b;
  }
  friend modint operator^(modint a, int b) { return a ^= b; }
  friend bool operator==(modint a, int b) { return a.x == b; }
  friend bool operator!=(modint a, int b) { return a.x != b; }
  bool operator!() { return !x; }
  modint operator-() { return x ? 1000000007 - x : 0; }
};
int h, m, n;
struct pii {
  int x;
  modint y;
  bool operator<(const pii &b) const { return x < b.x; }
};
set<pii> val[500005 << 2];
int mn[500005 << 2];
struct node {
  int h, l, r, s;
  bool operator<(const node &b) const { return h > b.h; }
} a[500005];
inline void pushup(int p) { mn[p] = min(mn[p << 1], mn[p << 1 | 1]); }
void build(int p, int l, int r) {
  if (l == r) {
    val[p].insert((pii){h + 1, 1});
    mn[p] = h + 1;
    return;
  }
  int mid = l + r >> 1;
  build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r), pushup(p);
}
modint ask(int p, int l, int r, int nl, int nr, int lim) {
  if (nl > nr) return 0;
  if (mn[p] > lim) return 0;
  modint res = 0;
  if (l == r) {
    while (val[p].size()) {
      pii tmp = *val[p].begin();
      if (tmp.x > lim) break;
      val[p].erase(tmp);
      res += tmp.y;
    }
    if (val[p].size())
      mn[p] = (*val[p].begin()).x;
    else
      mn[p] = 2147483647;
    return res;
  }
  int mid = l + r >> 1;
  if (nl <= mid) res += ask(p << 1, l, mid, nl, nr, lim);
  if (nr > mid) res += ask(p << 1 | 1, mid + 1, r, nl, nr, lim);
  pushup(p);
  return res;
}
void mdf(int p, int l, int r, int x, pii y) {
  if (l == r) {
    val[p].insert(y);
    mn[p] = (*val[p].begin()).x;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    mdf(p << 1, l, mid, x, y);
  else
    mdf(p << 1 | 1, mid + 1, r, x, y);
  pushup(p);
}
modint res;
void dfs(int p, int l, int r) {
  if (l == r) {
    for (auto it : val[p]) res += it.y;
    return;
  }
  int mid = l + r >> 1;
  dfs(p << 1, l, mid), dfs(p << 1 | 1, mid + 1, r);
}
void print() {
  dfs(1, 1, m);
  cout << res.x;
  exit(0);
}
signed main() {
  memset(mn, 127, sizeof mn);
  h = read(), m = read(), n = read();
  for (register int i = (1); i <= (n); ++i)
    a[i].h = read(), a[i].l = read(), a[i].r = read(), a[i].s = read();
  sort(a + 1, a + n + 1), build(1, 1, m);
  for (register int i = (1); i <= (n); ++i) {
    modint cnt = ask(1, 1, m, a[i].l, a[i].r, a[i].s + a[i].h);
    if (a[i].l == 1)
      mdf(1, 1, m, a[i].r + 1, (pii){a[i].h, 2 * cnt});
    else if (a[i].r == m)
      mdf(1, 1, m, a[i].l - 1, (pii){a[i].h, 2 * cnt});
    else
      mdf(1, 1, m, a[i].l - 1, (pii){a[i].h, cnt}),
          mdf(1, 1, m, a[i].r + 1, (pii){a[i].h, cnt});
  }
  dfs(1, 1, m);
  cout << res.x;
  return 0;
}
