#include <bits/stdc++.h>
using namespace std;
inline int nextInt() {
  int Int;
  cin >> Int;
  return Int;
}
template <typename T>
void maximize(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
void minimize(T &a, T b) {
  if (a > b) a = b;
}
const int mod1 = 1e9 + 7, mod2 = 1e9 + 3, N = 3e5 + 8;
const long long base = 31;
vector<string> V;
vector<pair<int, int> > Vh;
map<pair<int, int>, int> mp;
vector<int> m1[N];
pair<int, int> m2[N];
pair<int, int> f[N];
string s1, s2;
stack<int> st;
int nn, low[N], num[N], cnt = 0, sp[N], cc = 0, cal[N];
vector<int> E[N];
void dfs(int u) {
  st.push(u);
  low[u] = num[u] = ++cnt;
  for (int i = 0; i < m1[u].size(); i++) {
    int v = m1[u][i];
    if (sp[v]) continue;
    if (num[v] == 0) {
      dfs(v);
      minimize(low[u], low[v]);
    } else
      minimize(low[u], num[v]);
  }
  if (low[u] == num[u]) {
    int v;
    cc++;
    do {
      v = st.top();
      sp[v] = cc;
      minimize(f[cc], m2[v]);
      st.pop();
    } while (v != u);
  }
}
void make_edge() {
  for (int i = 0; i < nn; i++)
    for (int j = 0; j < m1[i].size(); j++) E[sp[i]].push_back(sp[m1[i][j]]);
}
pair<int, int> F(int i) {
  if (cal[i] != 0) return f[i];
  cal[i] = 1;
  for (int j = 0; j < E[i].size(); j++) {
    int k = E[i][j];
    minimize(f[i], F(k));
  }
  return f[i];
}
int main() {
  ios::sync_with_stdio(false);
  int n = nextInt(), m = -1;
  V.resize(n);
  Vh.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> V[i];
    pair<int, int> h1(0, 0);
    int c1 = 0;
    for (int j = 0; j < V[i].size(); j++) {
      if (V[i][j] >= 'A' && V[i][j] <= 'Z') V[i][j] -= 'A' - 'a';
      h1.first = (h1.first * base + V[i][j] - 'a' + 1) % mod1;
      h1.second = (h1.second * base + V[i][j] - 'a' + 1) % mod2;
      if (V[i][j] == 'r') c1++;
    }
    if (mp.find(h1) == mp.end()) {
      int tmp = mp.size();
      mp[h1] = tmp;
    }
    m2[mp[h1]] = pair<int, int>(c1, V[i].size());
    Vh[i] = h1;
  }
  cin >> m;
  while (m--) {
    cin >> s1;
    pair<int, int> h1(0, 0), h2(0, 0);
    int c1 = 0, c2 = 0;
    for (int i = 0; i < s1.size(); i++) {
      if (s1[i] >= 'A' && s1[i] <= 'Z') s1[i] -= 'A' - 'a';
      h1.first = (h1.first * base + s1[i] - 'a' + 1) % mod1;
      h1.second = (h1.second * base + s1[i] - 'a' + 1) % mod2;
      if (s1[i] == 'r') c1++;
    }
    cin >> s2;
    for (int i = 0; i < s2.size(); i++) {
      if (s2[i] >= 'A' && s2[i] <= 'Z') s2[i] -= 'A' - 'a';
      h2.first = (h2.first * base + s2[i] - 'a' + 1) % mod1;
      h2.second = (h2.second * base + s2[i] - 'a' + 1) % mod2;
      if (s2[i] == 'r') c2++;
    }
    if (mp.find(h1) == mp.end()) {
      int tmp = mp.size();
      mp[h1] = tmp;
    }
    if (mp.find(h2) == mp.end()) {
      int tmp = mp.size();
      mp[h2] = tmp;
    }
    m1[mp[h1]].push_back(mp[h2]);
    m2[mp[h1]] = pair<int, int>(c1, s1.size());
    m2[mp[h2]] = pair<int, int>(c2, s2.size());
  }
  for (int i = 0; i < N; i++) f[i] = pair<int, int>(mod1, mod1);
  nn = mp.size();
  for (int i = 0; i < nn; i++)
    if (num[i] == 0) dfs(i);
  make_edge();
  long long ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    pair<int, int> tmp = F(sp[mp[Vh[i]]]);
    ans1 += tmp.first;
    ans2 += tmp.second;
  }
  cout << ans1 << ' ' << ans2;
}
