#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v0, v1;
vector<int> C;
vector<long long> dp0, dp1;
long long Pow2(int n) {
  long long y = 1, x = 2;
  while (n) {
    if (n % 2) y = (y * x) % 1000000007;
    x = (x * x) % 1000000007;
    n /= 2;
  }
  return y;
}
void SortAndRemoveDuplicates(vector<int>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
bool IsPresent(vector<int>& v, int x) {
  int i = lower_bound(v.begin(), v.end(), x) - v.begin();
  return i < v.size() && v[i] == x;
}
int GetCompressedValue(vector<int>& v, int x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
void TakeInputSegments(int n, vector<pair<int, int> >& a, vector<int>& v) {
  for (int x = 1; x <= n; ++x) {
    int i, j;
    scanf("%d%d", &i, &j);
    a.push_back(make_pair(i, j));
    v.push_back(j);
    v.push_back(i - 1);
  }
}
void PreProcessSegments(vector<pair<int, int> >& a, vector<int>& c,
                        vector<vector<int> >& v) {
  v.resize(c.size());
  for (auto p : a) {
    int i, j;
    tie(i, j) = p;
    int cj = GetCompressedValue(c, j);
    v[cj].push_back(i);
  }
  for (int i = 0; i < v.size(); ++i) SortAndRemoveDuplicates(v[i]);
}
void TakeInputsAndPreProcess() {
  int k, n, m;
  vector<pair<int, int> > a, b;
  scanf("%d%d%d", &k, &n, &m);
  C.push_back(0);
  C.push_back(k);
  TakeInputSegments(n, a, C);
  TakeInputSegments(m, b, C);
  SortAndRemoveDuplicates(C);
  PreProcessSegments(a, C, v0);
  PreProcessSegments(b, C, v1);
  dp0.resize(C.size());
  dp1.resize(C.size());
}
void Update(vector<long long>& dp, long long i, long long val, long long& s) {
  val = (1000000007 + val) % 1000000007;
  dp[i] = (dp[i] + val) % 1000000007;
  s = (s + val) % 1000000007;
}
void UpdateLeftEnd(vector<long long>& dp, vector<int>& v, long long& k,
                   long long& s) {
  for (auto x : v)
    for (; C[k] < x; ++k) Update(dp, k, -dp[k], s);
}
int main() {
  TakeInputsAndPreProcess();
  for (long long i = 1, k0 = 0, k1 = 0, s0 = 0, s1 = 0; i < C.size(); ++i) {
    long long c = (Pow2(C[i] - C[i - 1] - 1) + 1000000007 - 1) % 1000000007,
              p0 = i == 1 ? 1ll : s0, p1 = i == 1 ? 1ll : s1;
    if (i != 1) {
      c = (c * (s0 + s1)) % 1000000007;
    }
    Update(dp0, i, c, s0);
    Update(dp1, i, c, s1);
    Update(dp0, i - 1, p1, s0);
    Update(dp1, i - 1, p0, s1);
    UpdateLeftEnd(dp0, v1[i], k0, s0);
    UpdateLeftEnd(dp1, v0[i], k1, s1);
  }
  long long ans = 0;
  for (int i = 0; i < C.size(); ++i) ans = (ans + dp0[i] + dp1[i]) % 1000000007;
  printf("%lld\n", ans);
  return 0;
}
