#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 20;
const long long oo = 1e18 + 20;
const int MOD = 998244353;
inline int mul(int a, int b) { return 1ll * a * b % MOD; }
inline int add(int a, int b) { return a + b < MOD ? a + b : a + b - MOD; }
pair<long long, long long> get(string &s) {
  return {count(s.begin(), s.end(), 'r'), s.size()};
}
map<string, int> ID;
int add(string &s) {
  if (ID.count(s)) return ID[s];
  int t = ID.size();
  return ID[s] = t;
}
vector<int> g[N];
pair<long long, long long> val[N], v[N];
int id[N], tag;
int scc(int n) {
  vector<int> dfn(n), low(n), in_stack(n);
  stack<int> st;
  tag = 0;
  function<void(int, int &)> dfs = [&](int u, int &t) {
    dfn[u] = low[u] = ++t;
    st.push(u);
    in_stack[u] = true;
    for (auto &v : g[u]) {
      if (!dfn[v]) {
        dfs(v, t);
        low[u] = min(low[u], low[v]);
      } else if (in_stack[v])
        low[u] = min(low[u], dfn[v]);
    }
    if (low[u] == dfn[u]) {
      int z;
      v[tag] = {INT_MAX, INT_MAX};
      do {
        z = st.top();
        st.pop();
        v[tag] = min(v[tag], val[z]);
        id[z] = tag;
        in_stack[z] = false;
      } while (z != u);
      tag++;
    }
  };
  for (int u = 0, t; u < n; ++u) {
    if (!dfn[u]) dfs(u, t = 0);
  }
  return tag;
}
vector<int> g2[N];
pair<long long, long long> operator+(const pair<long long, long long> &a,
                                     const pair<long long, long long> &b) {
  return {a.first + b.first, a.second + b.second};
}
pair<long long, long long> dp[N];
pair<long long, long long> go(int u) {
  pair<long long, long long> &r = dp[u];
  if (r.second == -1) {
    r = v[u];
    for (int v : g2[u]) {
      r = min(r, go(v));
    }
  }
  return r;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  while (cin >> n) {
    vector<string> V(n);
    for (auto &x : V) {
      cin >> x;
      for (char &c : x) c = tolower(c);
      val[add(x)] = get(x);
    }
    int q;
    cin >> q;
    while (q--) {
      string a, b;
      cin >> a >> b;
      for (char &c : a) c = tolower(c);
      for (char &c : b) c = tolower(c);
      int ida = add(a), idb = add(b);
      val[ida] = get(a);
      val[idb] = get(b);
      g[ida].push_back(idb);
    }
    n = ID.size();
    scc(N);
    for (int i = 0; i < N; i++) {
      for (auto v : g[i]) {
        if (id[i] != id[v]) {
          g2[id[i]].push_back(id[v]);
        }
      }
    }
    for (int i = 0; i < N; i++) dp[i] = {-1, -1};
    pair<long long, long long> ans = {0, 0};
    for (auto &x : V) {
      ans = ans + go(id[add(x)]);
    }
    cout << ans.first << " " << ans.second << '\n';
  }
}
