#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

struct T{
	int start, end;
};

T getT(){
	int a, b, c, d;
	scanf("%d:%d-%d:%d", &a, &b, &c, &d);
	T ret;
	ret.start = a * 60 + b;
	ret.end = c * 60 + d;
	return ret;
}

vector<T> getTs(){
	int n;
	scanf("%d", &n);
	vector<T> v;
	FOR(i, n) v.push_back(getT());
	return v;
}

int main(){
	auto f = getTs();
	vector<int> teacher(sz(f)), student(sz(f));
	int n; scanf("%d", &n);
	FOR(i, n){
		vector<int> cur;
		auto a = getTs();
		for (auto t : a) {
			FOR(i, sz(f)){
				if (t.start <= f[i].start && f[i].end <= t.end) teacher[i]++;
			}
		}
	}

	int m; scanf("%d", &m);
	FOR(i, m){
		vector<int> cur;
		auto a = getTs();
		for (auto t : a) {
			FOR(i, sz(f)){
				if (t.start <= f[i].start && f[i].end <= t.end) student[i]++;
			}
		}
	}

	int ans = 0;
	FOR(i, sz(f)){
		ans += min(teacher[i], student[i]);
	}
	cout << ans << endl;

}