#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, mod = 1e9 + 7, inf = 2e9;
int h, n, m, k, t[4 * N];
vector<pair<int, int> > q[4 * N];
int cur;
pair<pair<int, int>, pair<int, int> > a[N];
void build(int v, int l, int r) {
  if (l == r) {
    q[v].push_back(make_pair(inf, 0));
    return;
  }
  int mid = (r + l) >> 1;
  build(v + v, l, mid);
  build(v + v + 1, mid + 1, r);
}
void upd(int v, int l, int r, int pos, int h, int val) {
  if (!val) {
    return;
  }
  if (l == r) {
    t[v] = h;
    q[v].push_back(make_pair(h, val));
    return;
  }
  int mid = (r + l) >> 1;
  if (pos <= mid) {
    upd(v + v, l, mid, pos, h, val);
  } else {
    upd(v + v + 1, mid + 1, r, pos, h, val);
  }
  t[v] = min(t[v + v], t[v + v + 1]);
}
void get(int v, int l, int r, int tl, int tr, int h) {
  if (t[v] > h) {
    return;
  }
  if (tl <= l && r <= tr) {
    if (l == r) {
      while (!q[v].empty()) {
        auto it = q[v].back();
        if (it.first <= h) {
          cur += it.second;
          if (cur >= mod) {
            cur -= mod;
          }
          q[v].pop_back();
        } else {
          break;
        }
      }
      t[v] = q[v].back().first;
      return;
    }
    int mid = (r + l) >> 1;
    get(v + v, l, mid, tl, tr, h);
    get(v + v + 1, mid + 1, r, tl, tr, h);
  } else {
    int mid = (r + l) >> 1;
    if (tl <= mid) {
      get(v + v, l, mid, tl, tr, h);
    }
    if (tr > mid) {
      get(v + v + 1, mid + 1, r, tl, tr, h);
    }
  }
  t[v] = min(t[v + v], t[v + v + 1]);
}
void dfs(int v, int l, int r) {
  if (l == r) {
    for (auto it : q[v]) {
      cur += it.second;
      if (cur >= mod) {
        cur -= mod;
      }
    }
    return;
  }
  int mid = (r + l) >> 1;
  dfs(v + v, l, mid);
  dfs(v + v + 1, mid + 1, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> m >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first.first >> a[i].second.first >> a[i].second.second >>
        a[i].first.second;
  }
  build(1, 1, m);
  for (int i = 1; i <= m; i++) {
    upd(1, 1, m, i, h + 1, 1);
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    cur = 0;
    get(1, 1, m, a[i].second.first, a[i].second.second,
        a[i].first.first + a[i].first.second);
    if (a[i].second.first == 1) {
      cur <<= 1;
      if (cur >= mod) {
        cur -= mod;
      }
      upd(1, 1, m, a[i].second.second + 1, a[i].first.first, cur);
    } else if (a[i].second.second == m) {
      cur <<= 1;
      if (cur >= mod) {
        cur -= mod;
      }
      upd(1, 1, m, a[i].second.first - 1, a[i].first.first, cur);
    } else {
      upd(1, 1, m, a[i].second.first - 1, a[i].first.first, cur);
      upd(1, 1, m, a[i].second.second + 1, a[i].first.first, cur);
    }
  }
  cur = 0;
  dfs(1, 1, m);
  cout << cur;
}
