#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const long long mod = 1e9 + 7;
int H, w, n;
struct barrier {
  int u, l, r, s;
};
bool operator<(barrier a, barrier b) { return a.u > b.u; }
vector<barrier> B;
struct node {
  pair<int, int> p;
  set<int> nodes;
} seg[4 * maxn];
void build(int idx, int i, int j) {
  if (i == j) {
    seg[idx].nodes.insert({INT_MAX});
    seg[idx].p = {*seg[idx].nodes.begin(), i};
    return;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  build(left, i, mid);
  build(right, mid + 1, j);
  seg[idx].p = min(seg[left].p, seg[right].p);
}
void update(int idx, int i, int j, int pos, int val, int type) {
  if (i == j) {
    if (type)
      seg[idx].nodes.insert(val);
    else
      seg[idx].nodes.erase(val);
    seg[idx].p = {*seg[idx].nodes.begin(), i};
    return;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  if (pos <= mid)
    update(left, i, mid, pos, val, type);
  else
    update(right, mid + 1, j, pos, val, type);
  seg[idx].p = min(seg[left].p, seg[right].p);
}
pair<int, int> query(int idx, int i, int j, int l, int r) {
  if (i > j || j < l || r < i || l > r) return {INT_MAX, -1};
  if (l <= i && j <= r) return seg[idx].p;
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  return min(query(left, i, mid, l, r), query(right, mid + 1, j, l, r));
}
vector<int> dag[maxn];
int cur;
map<pair<int, int>, int> id;
long long dp[maxn];
long long f(int v) {
  if (dp[v] == -1) {
    if (v == cur) return dp[v] = 1;
    dp[v] = 0;
    for (auto u : dag[v]) dp[v] = (dp[v] + f(u)) % mod;
  }
  return dp[v];
}
long long solve() {
  long long ans = 0;
  sort(B.begin(), B.end());
  build(1, 1, w);
  for (int i = 1; i <= w; i++) {
    update(1, 1, w, i, H + 1, 1);
    id[{H + 1, i}] = ++cur;
  }
  for (auto i : B) {
    int h = i.u;
    int l = i.l;
    int r = i.r;
    int s = i.s;
    pair<int, int> q = query(1, 1, w, l, r);
    vector<int> nodes;
    while (q.first != INT_MAX && q.first <= h + s) {
      int u = id[{q.first, q.second}];
      update(1, 1, w, q.second, q.first, 0);
      nodes.push_back(u);
      q = query(1, 1, w, l, r);
    }
    if (l == 1) {
      int R = r + 1;
      update(1, 1, w, R, h, 1);
      update(1, 1, w, R, h, 1);
      id[{h, R}] = ++cur;
      for (auto k : nodes)
        for (int it = 0; it <= 1; it++) dag[k].push_back(id[{h, R}]);
    } else if (r == w) {
      int L = l - 1;
      update(1, 1, w, L, h, 1);
      update(1, 1, w, L, h, 1);
      id[{h, L}] = ++cur;
      for (auto k : nodes)
        for (int it = 0; it <= 1; it++) dag[k].push_back(id[{h, L}]);
    } else {
      int L = l - 1;
      int R = r + 1;
      update(1, 1, w, L, h, 1);
      update(1, 1, w, R, h, 1);
      id[{h, L}] = ++cur;
      id[{h, R}] = ++cur;
      for (auto k : nodes) {
        dag[k].push_back(id[{h, L}]);
        dag[k].push_back(id[{h, R}]);
      }
    }
  }
  int l = 1;
  int r = w;
  pair<int, int> q = query(1, 1, w, l, r);
  int v = ++cur;
  vector<int> nodes;
  while (q.first != INT_MAX) {
    int u = id[{q.first, q.second}];
    update(1, 1, w, q.second, q.first, 0);
    nodes.push_back(u);
    q = query(1, 1, w, l, r);
  }
  for (auto k : nodes) dag[k].push_back(v);
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= w; i++) ans = (ans + f(id[{H + 1, i}])) % mod;
  return ans;
}
int main() {
  cin.sync_with_stdio(false);
  cin >> H >> w >> n;
  for (int i = 1; i <= n; i++) {
    int u, l, r, s;
    cin >> u >> l >> r >> s;
    B.push_back({u, l, r, s});
  }
  cout << solve() << '\n';
  return 0;
}
