#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int Maxn = 600005, Maxm = 200005;
struct Trie {
  Trie *nxt[26];
  int v;
} * root, T[Maxn], *Null;
struct pair_ {
  int l, r;
  friend bool operator<(const pair_ &a, const pair_ &b) {
    if (a.l == b.l)
      return a.r < b.r;
    else
      return a.l < b.l;
  }
} aa[Maxn], bb[Maxn], f[Maxn];
char s[Maxn];
int n, m, tot;
int a[Maxn], xx[Maxn], yy[Maxn];
int to[Maxm], _cnt, nxt[Maxm], head[Maxn];
inline void AddEdge(int x, int y) {
  to[++_cnt] = y, nxt[_cnt] = head[x], head[x] = _cnt;
}
int scc[Maxn], scc_size;
int dfn[Maxn], low[Maxn], nn, ttime;
int stk[Maxn], top;
bool instk[Maxn];
void tarjan(int u) {
  dfn[u] = low[u] = ++ttime;
  instk[u] = 1, stk[++top] = u;
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = to[i];
    if (!dfn[v]) {
      tarjan(v);
      if (low[v] < low[u]) low[u] = low[v];
    } else if (instk[v] && dfn[v] < low[u])
      low[u] = dfn[v];
  }
  if (dfn[u] == low[u]) {
    scc_size++;
    int v;
    do {
      v = stk[top--];
      if (aa[v] < bb[scc_size]) bb[scc_size] = aa[v];
      instk[v] = false;
      scc[v] = scc_size;
    } while (u ^ v);
  }
}
void dfs(int x) {
  if (~f[x].l) return;
  f[x].l = bb[x].l;
  f[x].r = bb[x].r;
  for (int i = head[x]; i != -1; i = nxt[i])
    dfs(to[i]), (f[to[i]] < f[x]) ? (f[x] = f[to[i]]) : (pair_){-1, -1};
}
inline void CreateNode(char *str) {
  int len = strlen(str);
  Trie *p = root, *q;
  for (int i = 0; i < len; ++i) {
    int id = str[i] - 'a';
    if (p->nxt[id] == Null) {
      q = &T[tot++];
      q->v = -1;
      for (int j = 0; j < 26; ++j) q->nxt[j] = Null;
      p->nxt[id] = q;
      p = p->nxt[id];
    } else
      p = p->nxt[id];
  }
  p->v = nn++;
}
inline int find(char *str) {
  int len = strlen(str);
  Trie *p = root;
  for (int i = 0; i < len; ++i) {
    int id = str[i] - 'a';
    p = p->nxt[id];
    if (p == Null) return -1;
  }
  return p->v;
}
int main() {
  _cnt = -1;
  root = Null = &T[tot++];
  root->v = -1;
  for (int i = 0; i < 26; ++i) root->nxt[i] = Null;
  nn = 0;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%s", s);
    int res = 0, len = strlen(s), tmp;
    for (int i = 0; i < len; ++i)
      if ((s[i] += (s[i] < 'a') << 5) == 'r') ++res;
    if (~(tmp = find(s)))
      a[i] = tmp;
    else {
      a[i] = nn;
      aa[nn].l = res, aa[nn].r = len;
      bb[nn].l = 1e6, bb[nn].r = 1e6;
      f[nn].l = -1;
      CreateNode(s);
    }
  }
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    int res = 0, len = strlen(s), tmp;
    for (int i = 0; i < len; ++i)
      if ((s[i] += (s[i] < 'a') << 5) == 'r') ++res;
    if (~(tmp = find(s)))
      xx[i] = tmp;
    else {
      xx[i] = nn;
      aa[nn].l = res, aa[nn].r = len;
      bb[nn].l = 1e6, bb[nn].r = 1e6;
      f[nn].l = -1;
      CreateNode(s);
    }
    scanf("%s", s);
    res = 0, len = strlen(s);
    for (int i = 0; i < len; ++i)
      if ((s[i] += (s[i] < 'a') << 5) == 'r') ++res;
    if (~(tmp = find(s)))
      yy[i] = tmp;
    else {
      yy[i] = nn;
      aa[nn].l = res, aa[nn].r = len;
      bb[nn].l = 1e6, bb[nn].r = 1e6;
      f[nn].l = -1;
      CreateNode(s);
    }
    AddEdge(xx[i], yy[i]);
  }
  bb[nn].l = 1e6, bb[nn].r = 1e6;
  f[nn].l = -1, top = scc_size = ttime = 0;
  memset(dfn, 0, sizeof(dfn));
  for (int i = 0; i < nn; ++i)
    if (!dfn[i]) tarjan(i);
  _cnt = -1;
  memset(head, -1, sizeof(head));
  for (int i = 0; i < n; ++i)
    if (scc[xx[i]] != scc[yy[i]]) AddEdge(scc[xx[i]], scc[yy[i]]);
  for (int i = 1; i <= scc_size; ++i)
    if (!~f[i].l) dfs(i);
  long long ans1 = 0, ans2 = 0;
  for (int i = 0; i < m; ++i) ans1 += f[scc[a[i]]].l, ans2 += f[scc[a[i]]].r;
  printf("%lld %lld\n", ans1, ans2);
  return 0;
}
