#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
const long long maxn = 1e5 + 5, mod = 1e9 + 7;
struct node {
  long long h, l, r, s;
} e[maxn];
struct event {
  long long id, h, opt;
} b[maxn << 1];
struct tree {
  long long h, id;
  bool operator<(const tree a) const { return h > a.h; }
};
set<tree> a[maxn << 2];
long long height, ID, tot, H, w, n, dp[maxn];
inline void init() {
  H = read();
  w = read();
  n = read();
  for (long long i = 1; i <= n; i++) {
    long long h = read(), l = read(), r = read(), s = read();
    e[i] = (node){h, l, r, s};
    b[++tot] = (event){i, h, 1};
    if (h + s <= H) b[++tot] = (event){i, h + s + 1, 0};
  }
}
inline bool cmp(event a, event b) {
  if (a.h == b.h) return a.opt < b.opt;
  return a.h < b.h;
}
void update(long long k, long long l, long long r, long long x, long long y,
            long long opt) {
  long long mid = (l + r) >> 1;
  if (l == x && r == y) {
    if (opt == 0)
      a[k].erase((tree){height, ID});
    else
      a[k].insert((tree){height, ID});
    return;
  }
  if (mid >= y)
    update(k << 1, l, mid, x, y, opt);
  else if (mid < x)
    update(k << 1 | 1, mid + 1, r, x, y, opt);
  else
    update(k << 1, l, mid, x, mid, opt),
        update(k << 1 | 1, mid + 1, r, mid + 1, y, opt);
}
tree ans;
void query(long long k, long long l, long long r, long long x) {
  if (!a[k].empty()) {
    tree temp = *a[k].begin();
    if (temp < ans) {
      ans = temp;
    }
  }
  if (l == r) {
    return;
  }
  long long mid = (l + r) >> 1;
  if (mid >= x)
    query(k << 1, l, mid, x);
  else
    query(k << 1 | 1, mid + 1, r, x);
}
inline long long query(long long x) {
  ans = (tree){-1, -1};
  query(1, 1, w, x);
  if (ans.id == -1)
    return 1;
  else
    return dp[ans.id];
}
inline void solve() {
  sort(b + 1, b + 1 + tot, cmp);
  for (long long i = 1; i <= tot; i++) {
    ID = b[i].id;
    node now = e[ID];
    height = now.h;
    if (b[i].opt == 0) {
      update(1, 1, w, now.l, now.r, 0);
    } else {
      if (now.l == 1)
        dp[ID] = query(now.r + 1) * 2 % mod;
      else if (now.r == w)
        dp[ID] = query(now.l - 1) * 2 % mod;
      else
        (dp[ID] = query(now.l - 1) + query(now.r + 1)) %= mod;
      update(1, 1, w, now.l, now.r, 1);
    }
  }
  long long res = 0;
  for (long long i = 1; i <= w; i++) {
    (res += query(i)) %= mod;
  }
  writeln(res);
}
signed main() {
  init();
  solve();
  return 0;
}
