C++#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<queue>
#define ll long long
using namespace std;
int a, b, n, m, dp[4005][4005];
bool vis[4005][4005], vis1[4005][4005];
struct node{
int first_x, first_y;
int second_x, second_y;
};
node c[4005];
int main(){
//freopen("fraction.in","r",stdin);
//freopen("fraction.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
memset(vis, 1, sizeof(vis));
cin >> n >> m;
cin >> a;
for(int i = 1; i <= a; i ++){
ll x, y;
cin >> x >> y;
vis[x][y] = 0;
}
cin >> b;
for(int i = 1; i <= b; i ++){
cin >> c[i].first_x >> c[i].first_y >> c[i].second_x >> c[i].second_y;
vis1[c[i].second_y][c[i].second_y] = 1;
}
dp[1][1] = 1;
if(vis[1][1] == 0){
cout << -1;
return 0;
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
if((i == 1 && j == 1) || vis[i][j] == 0){
continue;
}
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
if(vis1[i][j] == 0){
for(int k = 1; k <= b; k ++){
if(c[k].second_x == i && c[k].second_y == j){
dp[i][j] += dp[c[k].first_x][c[k].first_y];
}
}
}
}
}
if(dp[n][m] == 0){
cout << -1;
return 0;
}
cout << dp[n][m];
//fclose(stdin);
//fclose(stdout);
return 0;
}