#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <cstring>
using namespace std;
#define LIM 600
#define INF 100000
int graph[LIM][LIM];
int q[LIM];
int front, rear;
int r[LIM][LIM];
int pre[LIM];
map<string, int> id;
int n, m, k;
int order = 2;
int s = 0, t = 1;
void create_graph() {
int i;
memset(graph, 0, sizeof(graph));
string plug, device, adaptor;
cin>>n;
for(i=0; i<n; i++) {
cin>>plug;
id[plug] = order++;
graph[id[plug]][t] = 1;
}
cin>>m;
for(i=0; i<m; i++) {
cin>>device>>plug;
if(!id[plug]) id[plug] = order++;
id[device] = order++;
graph[s][id[device]] = INF;
graph[id[device]][id[plug]] = 1;
}
cin>>k;
for(i=0; i<k; i++) {
cin>>adaptor>>plug;
if(!id[adaptor]) id[adaptor] = order++;
if(!id[plug]) id[plug] = order++;
graph[id[adaptor]][id[plug]] = INF;
}
memcpy(r, graph, sizeof(graph));
}
bool bfs(int s, int t, int n) {
int front = rear = 0;
int u, v;
memset(pre, -1, sizeof(pre));
q[rear++] = s;
while(rear > front) {
u = q[front++];
for(v=0; v<n; v++) {
if(pre[v] == -1 && r[u][v] > 0) {
pre[v] = u;
q[rear++] = v;
if(v == t) return true;
}
}
}
return false;
}
int max_flow(int s, int t, int n) {
int max = 0, inc, u, v;
while(true) {
if(!bfs(s, t, n)) break;
inc = INF;
for(v=t; v!=s; v=u) {
u = pre[v];
if(r[u][v] < inc) inc = r[u][v];
}
for(v=t; v!=s; v=u) {
u = pre[v];
r[u][v] -= inc;
r[v][u] += inc;
}
max += inc;
}
return max;
}
int main() {
create_graph();
int max = max_flow(s, t, order);
cout<<m - max<<endl;
}