#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Read(T &n) {
  char ch;
  bool flag = false;
  while (!isdigit(ch = getchar()))
    if (ch == '-') flag = true;
  for (n = ch ^ 48; isdigit(ch = getchar());
       n = (n << 1) + (n << 3) + (ch ^ 48))
    ;
  if (flag) n = -n;
}
const int MAXN = 100005;
const int MOD = 1000000007;
inline int inc(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline void iinc(int &a, int b) { a = inc(a, b); }
int H, n, m;
int lst[MAXN * 3], prv[MAXN * 3], h[MAXN * 3], num[MAXN * 3], id_cnt;
struct node {
  int mn, id;
  inline node operator+(const node &k) {
    node res;
    res.mn = min(mn, k.mn);
    if (res.mn == mn)
      res.id = id;
    else
      res.id = k.id;
    return res;
  }
} t[MAXN << 2];
inline int lc(int x) { return x << 1; }
inline int rc(int x) { return x << 1 | 1; }
void Build(int x, int head, int tail) {
  t[x].mn = H + 1;
  t[x].id = head;
  if (head == tail) return;
  int mid = head + tail >> 1;
  Build(lc(x), head, mid);
  Build(rc(x), mid + 1, tail);
}
void Change(int x, int head, int tail, int loc, int val) {
  if (head == tail) return t[x].mn = val, void();
  int mid = head + tail >> 1;
  if (loc <= mid) Change(lc(x), head, mid, loc, val);
  if (mid < loc) Change(rc(x), mid + 1, tail, loc, val);
  t[x] = t[lc(x)] + t[rc(x)];
}
node Query(int x, int head, int tail, int l, int r) {
  if (l <= head and tail <= r) return t[x];
  int mid = head + tail >> 1;
  if (r <= mid) return Query(lc(x), head, mid, l, r);
  if (mid < l) return Query(rc(x), mid + 1, tail, l, r);
  return Query(lc(x), head, mid, l, r) + Query(rc(x), mid + 1, tail, l, r);
}
struct bar {
  int h, l, r, s;
  inline bool operator<(const bar &k) const { return h > k.h; }
} a[MAXN];
inline void Delete(int x) { Change(1, 1, n, x, h[lst[x] = prv[lst[x]]]); }
inline void Insert(int x, int k) {
  prv[k] = lst[x];
  Change(1, 1, n, x, h[lst[x] = k]);
}
int main() {
  Read(H);
  Read(n);
  Read(m);
  Build(1, 1, n);
  id_cnt = n;
  for (register int i = 1; i <= n; i++) h[i] = H + 1, num[i] = 1, lst[i] = i;
  for (register int i = 1; i <= m; i++)
    Read(a[i].h), Read(a[i].l), Read(a[i].r), Read(a[i].s);
  sort(a + 1, a + m + 1);
  h[0] = INT_MAX;
  for (register int i = 1; i <= m; i++) {
    node x = Query(1, 1, n, a[i].l, a[i].r);
    int cnt = 0;
    while (x.mn <= a[i].h + a[i].s)
      iinc(cnt, num[lst[x.id]]), Delete(x.id),
          x = Query(1, 1, n, a[i].l, a[i].r);
    if (!cnt) continue;
    if (a[i].l == 1)
      id_cnt++, num[id_cnt] = inc(cnt, cnt), h[id_cnt] = a[i].h,
                Insert(a[i].r + 1, id_cnt);
    else if (a[i].r == n)
      id_cnt++, num[id_cnt] = inc(cnt, cnt), h[id_cnt] = a[i].h,
                Insert(a[i].l - 1, id_cnt);
    else
      id_cnt++, num[id_cnt] = cnt, h[id_cnt] = a[i].h,
                Insert(a[i].l - 1, id_cnt), id_cnt++, num[id_cnt] = cnt,
                h[id_cnt] = a[i].h, Insert(a[i].r + 1, id_cnt);
  }
  int ans = 0;
  for (register int i = 1; i <= n; i++)
    while (lst[i]) iinc(ans, num[lst[i]]), lst[i] = prv[lst[i]];
  cout << ans << endl;
  return 0;
}
