#include <bits/stdc++.h>
using namespace std;
struct node {
  long long ballcnt, height;
  node() {}
  node(long long __cnt, long long __h) {
    ballcnt = __cnt;
    height = __h;
  }
};
long long h, n, q;
struct segment_tree {
  long long minh[100100 << 2];
  stack<node> stk[100100];
  inline void make_it(long long p, long long x) {
    if (stk[x].size() == 0)
      minh[p] = 2000000000;
    else
      minh[p] = stk[x].top().height;
  }
  inline void pushup(long long p) {
    minh[p] = min(minh[(p << 1)], minh[(p << 1 | 1)]);
  }
  inline long long getsum(long long p, long long l, long long r, long long ql,
                          long long qr, long long limit) {
    if (minh[p] > limit) return 0;
    if (l == r) {
      long long ans = 0;
      while (stk[l].size() && stk[l].top().height <= limit) {
        (ans += stk[l].top().ballcnt) %= 1000000007;
        stk[l].pop();
      }
      make_it(p, l);
      return ans;
    }
    long long mid = (l + r) >> 1, ans = 0;
    if (ql <= mid) ans += getsum((p << 1), l, mid, ql, qr, limit);
    if (qr > mid) ans += getsum((p << 1 | 1), mid + 1, r, ql, qr, limit);
    pushup(p);
    return ans;
  }
  inline void insert(long long p, long long l, long long r, long long x,
                     node in) {
    if (l == r && r == x) {
      stk[l].push(in);
      make_it(p, x);
      return;
    }
    long long mid = (l + r) >> 1;
    if (x <= mid) insert((p << 1), l, mid, x, in);
    if (x > mid) insert((p << 1 | 1), mid + 1, r, x, in);
    pushup(p);
  }
  inline void solve(long long u, long long l, long long r, long long s) {
    long long cnt = getsum(1, 1, n, l, r, u + s);
    if (l == 1)
      insert(1, 1, n, r + 1, node((cnt << 1) % 1000000007, u));
    else if (r == n)
      insert(1, 1, n, l - 1, node((cnt << 1) % 1000000007, u));
    else
      insert(1, 1, n, l - 1, node(cnt, u)),
          insert(1, 1, n, r + 1, node(cnt, u));
  }
  inline long long getans() {
    long long ans = 0;
    for (long long i = 1; i <= n; i++)
      while (stk[i].size())
        (ans += stk[i].top().ballcnt) %= 1000000007, stk[i].pop();
    return ans;
  }
} seg;
struct board {
  long long u, l, r, s;
} x[100100];
bool operator<(const board &a, const board &b) { return a.u > b.u; }
inline void init() {
  scanf("%lld%lld%lld", &h, &n, &q);
  for (long long i = 1; i <= q; i++)
    scanf("%lld%lld%lld%lld", &x[i].u, &x[i].l, &x[i].r, &x[i].s);
  sort(x + 1, x + q + 1);
  for (long long i = 1; i <= n; i++) seg.insert(1, 1, n, i, node(1, h + 1));
}
signed main() {
  init();
  for (long long i = 1; i <= q; i++) seg.solve(x[i].u, x[i].l, x[i].r, x[i].s);
  printf("%lld\n", seg.getans());
}
