#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
  return out << "(" << p.first << ", " << p.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& v) {
  out << "[";
  for (long long i = 0; i < v.size(); i++) {
    if (i) out << ", ";
    out << v[i];
  }
  return out << "]";
}
const long long N = 1e5, T = 1e5 + 1, INF = 1e12, MOD = 1e9 + 7;
struct elem {
  long long y, l, r, s;
};
bool cmp(const elem& a, const elem& b) { return a.y > b.y; }
vector<elem> g;
vector<vector<pair<long long, long long>>> A;
vector<long long> f;
void build(long long v, long long tl, long long tr) {
  if (tl == tr) {
    if (A[tl].empty()) return void(f[v] = 0);
    return void(f[v] = tl);
  }
  long long tm = (tl + tr) / 2;
  build(v * 2, tl, tm);
  build(v * 2 + 1, tm + 1, tr);
  long long a = f[v * 2], b = f[v * 2 + 1];
  if (!b || a && A[a].back().first <= A[b].back().first)
    f[v] = a;
  else
    f[v] = b;
}
long long get_min(long long v, long long tl, long long tr, long long l,
                  long long r) {
  if (l > r) return 0;
  if (tl == l && tr == r) return f[v];
  long long tm = (tl + tr) / 2;
  long long a = get_min(v * 2, tl, tm, l, min(r, tm));
  long long b = get_min(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
  if (!b || a && A[a].back().first <= A[b].back().first)
    return a;
  else
    return b;
}
void update(long long v, long long tl, long long tr, long long it) {
  if (tl == tr) {
    if (A[tl].empty()) return void(f[v] = 0);
    return void(f[v] = tl);
  }
  long long tm = (tl + tr) / 2;
  if (tm >= it)
    update(v * 2, tl, tm, it);
  else
    update(v * 2 + 1, tm + 1, tr, it);
  long long a = f[v * 2], b = f[v * 2 + 1];
  if (!b || a && A[a].back().first <= A[b].back().first)
    f[v] = a;
  else
    f[v] = b;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long h, w, n, y, l, r, s;
  cin >> h >> w >> n;
  for (long long i = 0; i < n; i++) {
    cin >> y >> l >> r >> s;
    g.push_back({y, l, r, s});
  }
  A.resize(w + 1);
  for (long long i = 1; i <= w; i++) {
    A[i].push_back({h + 1, 1});
  }
  sort((g).begin(), g.end(), cmp);
  f.resize(4 * w);
  build(1, 1, w);
  for (long long i = 0; i < n; i++) {
    long long mn = get_min(1, 1, w, g[i].l, g[i].r);
    long long sz = 0;
    while (mn && A[mn].back().first - g[i].y <= g[i].s) {
      sz = (sz + A[mn].back().second) % MOD;
      A[mn].pop_back();
      update(1, 1, w, mn);
      mn = get_min(1, 1, w, g[i].l, g[i].r);
    }
    if (g[i].r == w) {
      A[g[i].l - 1].push_back({g[i].y, sz * 2 % MOD});
      update(1, 1, w, g[i].l - 1);
    } else if (g[i].l == 1) {
      A[g[i].r + 1].push_back({g[i].y, sz * 2 % MOD});
      update(1, 1, w, g[i].r + 1);
    } else {
      A[g[i].r + 1].push_back({g[i].y, sz});
      update(1, 1, w, g[i].r + 1);
      A[g[i].l - 1].push_back({g[i].y, sz});
      update(1, 1, w, g[i].l - 1);
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= w; i++) {
    for (auto x : A[i]) ans = (ans + x.second) % MOD;
  }
  cout << ans;
}
