#include <bits/stdc++.h>
using namespace std;
const int max_p = 3e5 + 5;
int R[max_p], len[max_p];
int low[max_p], dfn[max_p];
bool vis[max_p];
int belong[max_p], mi[max_p][2], scc, cnt;
vector<int> g[max_p];
stack<int> s;
void tarjan(int u) {
  low[u] = dfn[u] = ++cnt;
  s.push(u);
  vis[u] = 1;
  for (int v : g[u]) {
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (vis[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    ++scc;
    mi[scc][0] = R[u];
    mi[scc][1] = len[u];
    int v;
    do {
      v = s.top();
      s.pop();
      vis[v] = 0;
      belong[v] = scc;
      if (R[v] < mi[scc][0]) {
        mi[scc][0] = R[v];
        mi[scc][1] = len[v];
      } else if (R[v] == mi[scc][0] && len[v] < mi[scc][1])
        mi[scc][1] = len[v];
    } while (u != v);
  }
}
void dfs(int u) {
  vis[u] = 1;
  for (int v : g[u]) {
    if (!vis[v]) dfs(v);
    int fu = belong[u], fv = belong[v];
    if (mi[fv][0] < mi[fu][0]) {
      mi[fu][0] = mi[fv][0];
      mi[fu][1] = mi[fv][1];
    } else if (mi[fu][0] == mi[fv][0] && mi[fv][1] < mi[fu][1])
      mi[fu][1] = mi[fv][1];
  }
}
map<string, int> M;
vector<int> essay;
int idx;
int main() {
  int m, n;
  scanf("%d", &m);
  idx = 0;
  for (int i = 1; i <= m; i++) {
    string s;
    cin >> s;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    if (!M.count(s)) {
      M[s] = ++idx;
      int p = M[s];
      len[p] = s.length();
      for (int j = 0; j < len[p]; j++) {
        if (s[j] == 'r') R[p]++;
      }
    }
    essay.push_back(M[s]);
  }
  scanf("%d", &n);
  while (n--) {
    string s;
    cin >> s;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    if (!M.count(s)) {
      M[s] = ++idx;
      int p = M[s];
      len[p] = s.length();
      for (int j = 0; j < len[p]; j++) {
        if (s[j] == 'r') R[p]++;
      }
    }
    int u = M[s];
    cin >> s;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    if (!M.count(s)) {
      M[s] = ++idx;
      int p = M[s];
      len[p] = s.length();
      for (int j = 0; j < len[p]; j++) {
        if (s[j] == 'r') R[p]++;
      }
    }
    int v = M[s];
    g[u].push_back(v);
  }
  for (int i = 1; i <= idx; i++) {
    if (!dfn[i]) tarjan(i);
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= idx; i++) {
    if (!vis[i]) dfs(i);
  }
  long long ans[2] = {0, 0};
  for (int i : essay) {
    ans[0] += mi[belong[i]][0];
    ans[1] += mi[belong[i]][1];
  }
  printf("%lld %lld\n", ans[0], ans[1]);
  return 0;
}
