#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string conv(string s) {
  for (char &c : s) {
    c = tolower(c);
  }
  return s;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<string> a(n), dct;
  for (auto &x : a) {
    cin >> x;
    x = conv(x);
    dct.push_back(conv(x));
  }
  vector<pair<string, string>> elist;
  long long m;
  cin >> m;
  while (m--) {
    string u, v;
    cin >> u >> v;
    u = conv(u), v = conv(v);
    dct.push_back(u);
    dct.push_back(v);
    elist.emplace_back(u, v);
  }
  sort(dct.begin(), dct.end());
  dct.resize(unique(dct.begin(), dct.end()) - dct.begin());
  long long N = dct.size();
  vector<vector<long long>> g(N), rg(N);
  for (auto [u, v] : elist) {
    long long av = lower_bound(dct.begin(), dct.end(), u) - dct.begin();
    long long bv = lower_bound(dct.begin(), dct.end(), v) - dct.begin();
    g[av].push_back(bv);
    rg[bv].push_back(av);
  }
  vector<bool> vis(N);
  vector<long long> id(N);
  vector<long long> stk;
  function<void(long long, vector<long long> &)> dfs =
      [&](long long v, vector<long long> &vec) {
        vis[v] = true;
        for (long long u : g[v])
          if (!vis[u]) {
            dfs(u, vec);
          }
        vec.push_back(v);
      };
  for (long long i = 0; i < N; i++)
    if (!vis[i]) {
      dfs(i, stk);
    }
  g = rg;
  long long cid = 0;
  vis = vector<bool>(N);
  for (long long i = N - 1; i >= 0; i--)
    if (!vis[stk[i]]) {
      vector<long long> comp;
      dfs(stk[i], comp);
      for (long long x : comp) {
        id[x] = cid;
      }
      cid++;
    }
  g = vector<vector<long long>>(cid);
  for (auto [u, v] : elist) {
    long long av = lower_bound(dct.begin(), dct.end(), u) - dct.begin();
    long long bv = lower_bound(dct.begin(), dct.end(), v) - dct.begin();
    if (id[av] != id[bv]) {
      g[id[bv]].push_back(id[av]);
    }
  }
  vector<pair<long long, long long>> dp(cid, {1e9, 1e9});
  vis = vector<bool>(cid);
  vector<long long> ord;
  function<void(long long)> ts = [&](long long v) {
    vis[v] = true;
    for (long long u : g[v])
      if (!vis[u]) {
        ts(u);
      }
    ord.push_back(v);
  };
  for (long long i = 0; i < cid; i++)
    if (!vis[i]) {
      ts(i);
    }
  reverse(ord.begin(), ord.end());
  for (string s : dct) {
    long long v = lower_bound(dct.begin(), dct.end(), s) - dct.begin();
    long long cnt = 0;
    for (char c : s) {
      cnt += c == 'r';
    }
    dp[id[v]] = min(dp[id[v]], {cnt, s.size()});
  }
  for (long long v : ord) {
    for (long long u : g[v]) {
      dp[u] = min(dp[u], dp[v]);
    }
  }
  long long a1 = 0, a2 = 0;
  for (string s : a) {
    long long v = lower_bound(dct.begin(), dct.end(), s) - dct.begin();
    a1 += dp[id[v]].first;
    a2 += dp[id[v]].second;
  }
  cout << a1 << " " << a2;
}
