#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int maxn = 1048576;
int N;
int n, m, k;
pair<int, int> o[maxn];
vector<pair<int, pair<int, int> > > st, en;
int cf[maxn * 2];
int s[maxn * 2];
multiset<pair<int, int> > ss;
int dp[maxn];
void rlx(int seg, int ls, int rs) {
  if (cf[seg] == -1) return;
  int mid = (ls + rs) >> 1;
  cf[(seg + seg + 1)] = cf[seg];
  s[(seg + seg + 1)] = 1ll * cf[seg] * (mid - ls) % M;
  cf[(seg + seg + 2)] = cf[seg];
  s[(seg + seg + 2)] = 1ll * cf[seg] * (rs - mid) % M;
  cf[seg] = -1;
}
void upd(int seg) { s[seg] = (s[(seg + seg + 1)] + s[(seg + seg + 2)]) % M; }
void cng(int seg, int ls, int rs, int l, int r, int first) {
  if (r <= ls or rs <= l) return;
  if (l <= ls and rs <= r) {
    cf[seg] = first;
    s[seg] = 1ll * first * (rs - ls) % M;
    return;
  }
  rlx(seg, ls, rs);
  int mid = (ls + rs) >> 1;
  cng((seg + seg + 1), ls, mid, l, r, first);
  cng((seg + seg + 2), mid, rs, l, r, first);
  upd(seg);
}
int sum(int seg, int ls, int rs, int l, int r) {
  if (r <= ls or rs <= l or r <= l) return 0;
  if (l <= ls and rs <= r) return s[seg];
  rlx(seg, ls, rs);
  int mid = (ls + rs) >> 1;
  return (sum((seg + seg + 1), ls, mid, l, r) +
          sum((seg + seg + 2), mid, rs, l, r)) %
         M;
}
void rem(int l, int r) {
  ss.erase(ss.find({r - 1, 1}));
  ss.erase(ss.find({l, 0}));
}
void add(int l, int r) {
  cng(0, 0, N, l, r, 0);
  ss.insert({r - 1, 1});
  ss.insert({l, 0});
}
int nex(int l) {
  auto P = *ss.lower_bound({l, 0});
  if (P.second) return l;
  return P.first;
}
int main() {
  memset(cf, -1, sizeof cf);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  N = m + 3;
  ss.insert({N, 0});
  for (int a, b, c, d, i = 0; i < k; i++) {
    cin >> a >> b >> c >> d;
    o[i].first = c;
    o[i].second = b;
    st.push_back({c, {b, d + 1}});
    en.push_back({a, {b, d + 1}});
  }
  o[k++] = {0, 2};
  sort(o, o + k);
  sort(st.begin(), st.end());
  sort(en.begin(), en.end());
  cng(0, 0, N, m, m + 1, 1);
  for (int i = k - 1; i >= 0;) {
    vector<int> v, d;
    int lx = o[i].first;
    for (; en.size() and en.back().first > lx + 1; en.pop_back())
      rem(en.back().second.first, en.back().second.second);
    for (; i >= 0 and o[i].first == lx; i--) {
      int r = nex(o[i].second - 1);
      if (lx != n) dp[i] = sum(0, 0, N, o[i].second - 1, r);
      v.push_back(o[i].second);
      d.push_back(dp[i]);
    }
    for (int j = 0; j < v.size(); j++) cng(0, 0, N, v[j] - 1, v[j], d[j]);
    for (; st.size() and st.back().first >= lx; st.pop_back())
      add(st.back().second.first, st.back().second.second);
  }
  cout << dp[0] << endl;
  return 0;
}
