#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long ans1, ans2;
int n, m, cnt, ind, sz, top, scc;
int dfn[300005], low[300005], belong[300005], q[300005];
int id[300005], last[300005], lt[300005];
int len[300005], key[300005], mn[300005], lmn[300005];
bool vis[300005], inq[300005];
char ch[300005];
map<string, int> mp;
struct edge {
  int to, next;
} e[300005], ed[300005];
void insert(int u, int v) {
  e[++cnt].to = v;
  e[cnt].next = last[u];
  last[u] = cnt;
}
void ins(int u, int v) {
  ed[++cnt].to = v;
  ed[cnt].next = lt[u];
  lt[u] = cnt;
}
void tarjan(int x) {
  dfn[x] = low[x] = ++ind;
  inq[x] = 1;
  q[++top] = x;
  for (int i = last[x]; i; i = e[i].next)
    if (!dfn[e[i].to])
      tarjan(e[i].to), low[x] = min(low[x], low[e[i].to]);
    else if (inq[e[i].to])
      low[x] = min(low[x], dfn[e[i].to]);
  int now = 0;
  if (low[x] == dfn[x]) {
    scc++;
    while (now != x) {
      now = q[top--];
      inq[now] = 0;
      belong[now] = scc;
      if (key[now] < mn[scc] || (key[now] == mn[scc] && len[now] < lmn[scc]))
        mn[scc] = key[now], lmn[scc] = len[now];
    }
  }
}
void rebuild(int t) {
  cnt = 0;
  for (int i = 1; i <= t; i++)
    for (int j = last[i]; j; j = e[j].next)
      if (belong[i] != belong[e[j].to]) ins(belong[i], belong[e[j].to]);
}
void dfs(int x) {
  if (vis[x]) return;
  for (int i = lt[x]; i; i = ed[i].next) {
    int t = ed[i].to;
    dfs(t);
    if (mn[t] < mn[x] || (mn[t] == mn[x] && lmn[t] < lmn[x]))
      lmn[x] = lmn[t], mn[x] = mn[t];
  }
}
int main() {
  memset(mn, 127 / 3, sizeof(mn));
  memset(lmn, 127 / 3, sizeof(lmn));
  n = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch);
    int l = strlen(ch), k = 0;
    for (int j = 0; j < l; j++) {
      if (ch[j] >= 'A' && ch[j] <= 'Z') ch[j] = ch[j] - 'A' + 'a';
      if (ch[j] == 'r') k++;
    }
    int t = mp[ch];
    if (!t) t = mp[ch] = ++sz;
    len[t] = l;
    key[t] = k;
    id[i] = t;
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    scanf("%s", ch);
    int l = strlen(ch), k = 0;
    for (int j = 0; j < l; j++) {
      if (ch[j] >= 'A' && ch[j] <= 'Z') ch[j] = ch[j] - 'A' + 'a';
      if (ch[j] == 'r') k++;
    }
    int x = mp[ch];
    if (!x) x = mp[ch] = ++sz;
    len[x] = l;
    key[x] = k;
    scanf("%s", ch);
    l = strlen(ch), k = 0;
    for (int j = 0; j < l; j++) {
      if (ch[j] >= 'A' && ch[j] <= 'Z') ch[j] = ch[j] - 'A' + 'a';
      if (ch[j] == 'r') k++;
    }
    int y = mp[ch];
    if (!y) y = mp[ch] = ++sz;
    len[y] = l;
    key[y] = k;
    insert(x, y);
  }
  int t = mp.size();
  for (int i = 1; i <= t; i++)
    if (!dfn[i]) tarjan(i);
  rebuild(t);
  for (int i = 1; i <= scc; i++) dfs(i);
  for (int i = 1; i <= n; i++) {
    ans1 += mn[belong[id[i]]], ans2 += lmn[belong[id[i]]];
  }
  printf("%I64d %I64d\n", ans1, ans2);
  return 0;
}
