#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("unroll-loops")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 100;
const int INF = 1e9;
vector<int> g[N], rg[N], g2[N];
pair<int, int> val[N], ans[N];
vector<int> used(N), ord, comp(N);
void dfs1(int v) {
  used[v] = 1;
  for (auto u : g[v]) {
    if (!used[u]) dfs1(u);
  }
  ord.push_back(v);
}
void dfs2(int v, int c) {
  used[v] = 1;
  comp[v] = c;
  for (auto u : rg[v]) {
    if (!used[u]) dfs2(u, c);
  }
}
void dfs3(int v) {
  used[v] = 1;
  for (auto u : g2[v]) {
    if (!used[u]) {
      dfs3(u);
    }
    ans[v] = min(ans[v], ans[u]);
  }
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int i = 0; i < N; i++) {
    ans[i] = {INF, INF};
  }
  int n, m;
  cin >> n;
  vector<int> a(n);
  map<string, int> mp;
  int C = 0;
  auto f = [&](string &s) {
    for (auto &c : s) c = tolower(c);
    if (!mp.count(s)) {
      mp[s] = C;
      val[C] = {count(s.begin(), s.end(), 'r'), (int)s.size()};
      C++;
    }
    return mp[s];
  };
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    a[i] = f(s);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s, t;
    cin >> s >> t;
    g[f(s)].push_back(f(t));
    rg[f(t)].push_back(f(s));
  }
  for (int i = 0; i < C; i++) {
    if (!used[i]) dfs1(i);
  }
  reverse(ord.begin(), ord.end());
  fill(used.begin(), used.end(), 0);
  int k = C;
  C = 0;
  for (auto v : ord) {
    if (!used[v]) dfs2(v, C), C++;
  }
  for (int v = 0; v < k; v++) {
    ans[comp[v]] = min(ans[comp[v]], val[v]);
    for (auto u : g[v]) {
      if (comp[v] == comp[u]) {
        ans[comp[v]] = min(ans[comp[v]], val[u]);
      } else
        g2[comp[v]].push_back(comp[u]);
    }
  }
  fill(used.begin(), used.end(), 0);
  for (int i = 0; i < C; i++) {
    if (!used[i]) dfs3(i);
  }
  pair<long long, long long> res = {0, 0};
  for (auto x : a) {
    x = comp[x];
    res.first += ans[x].first;
    res.second += ans[x].second;
  }
  cout << res.first << ' ' << res.second << '\n';
}
