#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
const int mod = 1e9 + 7;
const int inf = 1e9;
int n, H, W, al[maxn], ar[maxn];
vector<pair<pair<int, int>, pair<int, int> > > a;
vector<pair<int, int> > vec;
pair<int, pair<int, int> > seg[maxn << 2];
pair<int, pair<int, int> > mx(pair<int, pair<int, int> > l,
                              pair<int, pair<int, int> > r) {
  pair<int, pair<int, int> > id = max(l, r);
  if (id.second.first == 0) id = min(l, r);
  return id;
}
void bld(int id, int s, int e) {
  if (e - s == 1) {
    seg[id] = make_pair(vec[s].second, make_pair(0ll, s));
    if (vec[s].second == 0) seg[id].second.first++;
    return;
  }
  int mid = (s + e) >> 1;
  bld((id << 1), s, mid);
  bld((id << 1 | 1), mid, e);
  seg[id] = mx(seg[(id << 1)], seg[(id << 1 | 1)]);
  return;
}
void upd(int id, int s, int e, int l, int r, int x) {
  if (r <= s || e <= l) return;
  if (l <= s && e <= r) {
    seg[id].second.first = x;
    return;
  }
  int mid = (s + e) >> 1;
  upd((id << 1), s, mid, l, r, x);
  upd((id << 1 | 1), mid, e, l, r, x);
  seg[id] = mx(seg[(id << 1)], seg[(id << 1 | 1)]);
  return;
}
pair<int, pair<int, int> > get(int id, int s, int e, int l, int r) {
  if (r <= s || e <= l) return make_pair(-1ll, make_pair(0ll, 0ll));
  if (l <= s && e <= r) return seg[id];
  int mid = (s + e) >> 1;
  return mx(get((id << 1), s, mid, l, r), get((id << 1 | 1), mid, e, l, r));
}
int Sum(int id, int s, int e) {
  if (e - s == 1) return seg[id].second.first;
  int mid = (s + e) >> 1;
  int x = Sum((id << 1), s, mid) + Sum((id << 1 | 1), mid, e);
  if (x >= mod) x -= mod;
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> H >> W >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first.first >> a[i].second.first >> a[i].second.second >>
        a[i].first.second;
    a[i].first.first = H - a[i].first.first + 1;
  }
  for (int i = 1; i <= W; i++) {
    vec.push_back(make_pair(i, 0));
  }
  sort((a).begin(), (a).end());
  for (int i = 0; i < n; i++) {
    if (a[i].second.first != 1) {
      vec.push_back(make_pair(a[i].second.first - 1, a[i].first.first));
    }
    if (a[i].second.second != W) {
      vec.push_back(make_pair(a[i].second.second + 1, a[i].first.first));
    }
  }
  sort((vec).begin(), (vec).end());
  for (int i = 0; i < n; i++) {
    if (a[i].second.first != 1) {
      al[i] = lower_bound((vec).begin(), (vec).end(),
                          make_pair(a[i].second.first - 1, a[i].first.first)) -
              vec.begin();
    }
    if (a[i].second.second != W) {
      ar[i] = lower_bound((vec).begin(), (vec).end(),
                          make_pair(a[i].second.second + 1, a[i].first.first)) -
              vec.begin();
    }
    if (a[i].second.first == 1) al[i] = ar[i];
    if (a[i].second.second == W) ar[i] = al[i];
  }
  int second = (int)vec.size();
  bld(1, 0, second);
  for (int i = 0; i < n; i++) {
    int x = 0, xl, xr;
    xl = lower_bound((vec).begin(), (vec).end(),
                     make_pair(a[i].second.first, -inf)) -
         vec.begin();
    xr = upper_bound((vec).begin(), (vec).end(),
                     make_pair(a[i].second.second, inf)) -
         vec.begin();
    pair<int, pair<int, int> > p = get(1, 0, second, xl, xr);
    while (a[i].first.first - p.first <= a[i].first.second &&
           p.second.first > 0) {
      upd(1, 0, second, p.second.second, p.second.second + 1, 0);
      x += p.second.first;
      if (x >= mod) x -= mod;
      p = get(1, 0, second, xl, xr);
    }
    if (al[i] == ar[i]) x <<= 1;
    if (x >= mod) x -= mod;
    upd(1, 0, second, ar[i], ar[i] + 1, x);
    upd(1, 0, second, al[i], al[i] + 1, x);
  }
  cout << Sum(1, 0, second);
  return 0;
}
