#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <sstream>
#include <string>
using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

template<class T, class U>
T lexical_cast(const U& from) {
  stringstream ss;
  ss << from;
  T to;
  ss >> to;
  return to;
}

pair<int, int> parse(const string &s) {
  // DEBUG(s);
  int st = 0;
  st += lexical_cast<int>(s.substr(0, 2)) * 60;
  st += lexical_cast<int>(s.substr(3, 2));

  int en = 0;
  en += lexical_cast<int>(s.substr(6, 2)) * 60;
  en += lexical_cast<int>(s.substr(9, 2));
  return make_pair(st, en);
}

int main() {
  int K; cin >> K;
  vector<pair<int, int>> A;
  for(int i = 0; i < K; ++i) {
    string s; cin >> s;
    A.push_back(parse(s));
  }
  int N; cin >> N;
  vector<vector<pair<int, int>>> B(N);
  for(int i = 0; i < N; ++i) {
    int k; cin >> k;
    for(int j = 0; j < k; ++j) {
      string s; cin >> s;
      B[i].push_back(parse(s));
    }
  }
  int M; cin >> M;
  vector<vector<pair<int, int>>> C(M);
  for(int i = 0; i < M; ++i) {
    int k; cin >> k;
    for(int j = 0; j < k; ++j) {
      string s; cin >> s;
      C[i].push_back(parse(s));
    }
  }
  int ans = 0;
  for(int i = 0; i < K; ++i) {
    int t = 0;
    for(int j = 0; j < N; ++j) {
      bool ok = false;
      for(auto item : B[j]) {
        if(item.first <= A[i].first && A[i].second <= item.second) ok = true;
      }
      if(ok) ++t;
    }
    int s = 0;
    for(int j = 0; j < M; ++j) {
      bool ok = false;
      for(auto item : C[j]) {
        if(item.first <= A[i].first && A[i].second <= item.second) ok = true;
      }
      if(ok) ++s;
    }
    ans += min(t, s);
  }
  cout << ans << endl;
}