#include <bits/stdc++.h>
using namespace std;
int t, n, m, mm;
string word[111111];
pair<string, string> dict[111111];
vector<string> s;
stack<int> S;
struct edge {
  int u, v;
} g[111111];
int p[333333], dfn[333333], low[333333], v[333333], f[333333];
pair<int, int> a[333333];
pair<long long, long long> ans;
queue<int> Q;
void tolow(string& s) {
  for (int i = 0; i < s.size(); i++)
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
}
int cmp(edge a, edge b) { return a.u < b.u; }
void dfs(int x) {
  dfn[x] = low[x] = t++;
  S.push(x);
  v[x] = 1;
  for (int i = p[x]; i < p[x + 1]; i++)
    if (!dfn[g[i].v]) {
      dfs(g[i].v);
      low[x] = min(low[x], low[g[i].v]);
    } else {
      if (v[g[i].v]) low[x] = min(low[x], dfn[g[i].v]);
    }
  if (dfn[x] == low[x]) {
    while (v[x]) {
      f[S.top()] = x;
      v[S.top()] = 0;
      S.pop();
    }
  }
}
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> word[i];
    tolow(word[i]);
    s.push_back(word[i]);
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> dict[i].first >> dict[i].second;
    tolow(dict[i].first);
    tolow(dict[i].second);
    s.push_back(dict[i].first);
    s.push_back(dict[i].second);
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  mm = 0;
  for (int i = 0; i < n; i++) {
    int lo = -1, hi = s.size();
    while (hi - lo > 1) {
      int mi = (lo + hi) / 2;
      if (s[mi] < dict[i].first)
        lo = mi;
      else
        hi = mi;
    }
    g[mm].v = hi;
    lo = -1, hi = s.size();
    while (hi - lo > 1) {
      int mi = (lo + hi) / 2;
      if (s[mi] < dict[i].second)
        lo = mi;
      else
        hi = mi;
    }
    g[mm++].u = hi;
  }
  sort(g, g + mm, cmp);
  t = 0;
  for (int i = 0; i < mm; i++)
    while (t <= g[i].u) p[t++] = i;
  while (t <= s.size()) p[t++] = mm;
  t = 0;
  for (int i = 0; i < s.size(); i++)
    if (!dfn[i]) dfs(i);
  for (int i = 0; i < s.size(); i++) a[i].first = -1;
  for (int i = 0; i < s.size(); i++) {
    t = 0;
    for (int j = 0; j < s[i].size(); j++)
      if (s[i][j] == 'r') t++;
    if (a[f[i]].first == -1 || t < a[f[i]].first ||
        t == a[f[i]].first && s[i].size() < a[f[i]].second)
      a[f[i]] = make_pair(t, s[i].size());
  }
  for (int i = 0; i < mm; i++) {
    g[i].u = f[g[i].u];
    g[i].v = f[g[i].v];
  }
  sort(g, g + mm, cmp);
  t = 0;
  for (int i = 0; i < mm; i++)
    while (t <= g[i].u) p[t++] = i;
  while (t <= s.size()) p[t++] = mm;
  for (int i = 0; i < s.size(); i++) {
    Q.push(i);
    v[i] = 1;
  }
  while (!Q.empty()) {
    int x = Q.front();
    v[x] = 0;
    Q.pop();
    for (int i = p[x]; i < p[x + 1]; i++)
      if (a[g[i].u] < a[g[i].v]) {
        a[g[i].v] = a[g[i].u];
        if (!v[g[i].v]) {
          Q.push(g[i].v);
          v[g[i].v] = 1;
        }
      }
  }
  ans = make_pair(0, 0);
  for (int i = 0; i < m; i++) {
    int lo = -1, hi = s.size();
    while (hi - lo > 1) {
      int mi = (lo + hi) / 2;
      if (s[mi] < word[i])
        lo = mi;
      else
        hi = mi;
    }
    ans.first += a[f[hi]].first;
    ans.second += a[f[hi]].second;
  }
  cout << ans.first << ' ' << ans.second << endl;
}
