#include <bits/stdc++.h>
using namespace std;
inline const int getint() {
  int r = 0, k = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') k = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) r = r * 10 + c - '0';
  return k * r;
}
inline const int max(const int &a, const int &b) { return a > b ? a : b; }
inline const int min(const int &a, const int &b) { return a < b ? a : b; }
const int N = 500005;
string tp;
map<string, int> mp;
char rdin[N];
int n, m, tot, d[N], ln[N], cnt, ihead[N], vis[N], mn[N], essay[N], FF[N],
    LL[N], scc, tm, top, q[N], len[N], belongs[N], U[N], V[N];
struct ED {
  int next, to;
} e[N * 4];
void add(int u, int v) {
  e[++cnt].next = ihead[u];
  ihead[u] = cnt;
  e[cnt].to = v;
}
int cal(char *s) {
  int len = strlen(s), ret = 0;
  for (int j = 0; j < (len); ++j)
    if (s[j] == 'r') ++ret;
  return ret;
}
int readin() {
  scanf("%s", rdin);
  int len = strlen(rdin);
  for (int j = 0; j < (len); ++j)
    if (rdin[j] >= 'A' && rdin[j] <= 'Z') rdin[j] = rdin[j] - 'A' + 'a';
  tp = rdin;
  if (mp[tp]) return mp[tp];
  mp[tp] = ++tot;
  ln[tot] = strlen(rdin);
  d[tot] = cal(rdin);
  return tot;
}
void dfs(int u) {
  vis[u] = 1;
  int v;
  for (int i = ihead[u]; i; i = e[i].next) {
    if (!vis[v = e[i].to]) dfs(v);
    if (mn[v] < mn[u] || (mn[v] == mn[u] && len[v] < len[u])) {
      mn[u] = mn[v];
      len[u] = len[v];
    }
  }
}
void tarjan(int u) {
  LL[u] = FF[u] = ++tm;
  vis[u] = 1;
  q[++top] = u;
  int v;
  for (int i = ihead[u]; i; i = e[i].next) {
    v = e[i].to;
    if (!FF[v])
      tarjan(v), LL[u] = min(LL[u], LL[v]);
    else if (vis[v])
      LL[u] = min(LL[u], FF[v]);
  }
  if (FF[u] == LL[u]) {
    ++scc;
    int x;
    do {
      x = q[top--];
      vis[x] = 0;
      belongs[x] = scc;
      if (d[x] < mn[scc] || (d[x] == mn[scc] && ln[x] < len[scc]))
        mn[scc] = d[x], len[scc] = ln[x];
    } while (x != u);
  }
}
void rebuild() {
  memset(vis, 0, sizeof(vis));
  memset(ihead, 0, sizeof(ihead));
  cnt = 0;
  for (int i = (1); i <= (m); ++i)
    if (belongs[U[i]] != belongs[V[i]]) add(belongs[U[i]], belongs[V[i]]);
}
int main() {
  n = getint();
  for (int i = (1); i <= (n); ++i) essay[i] = readin();
  m = getint();
  for (int i = (1); i <= (m); ++i) {
    int pos1 = readin(), pos2 = readin();
    add(pos1, pos2);
    U[i] = pos1, V[i] = pos2;
  }
  memset(mn, 0x3f, sizeof(mn));
  memset(len, 0x3f, sizeof(len));
  for (int i = (1); i <= (tot); ++i)
    if (!FF[i]) tarjan(i);
  rebuild();
  for (int i = (1); i <= (scc); ++i) dfs(i);
  long long ans1 = 0, ans2 = 0;
  for (int i = (1); i <= (n); ++i) {
    int pos = belongs[essay[i]];
    ans1 += mn[pos];
    ans2 += len[pos];
  }
  printf("%I64d %I64d\n", ans1, ans2);
  return 0;
}
