#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
inline int getBit(long long x, int pos) { return ((x >> pos) & 1); }
const double eps = 1e-9;
const double pi = acos(-1.0);
const int MAXN = (int)(5e5) + 10;
void toLowerCase(string &str) {
  int n = str.length();
  for (int i = 0; i < n; i++) {
    if ('A' <= str[i] && str[i] <= 'Z') {
      str[i] = (str[i] - 'A' + 'a');
    }
  }
}
int n, m, N;
char str[MAXN];
string words[MAXN];
map<string, int> mid;
string X[MAXN], Y[MAXN];
vector<int> g[MAXN];
long long Len[MAXN], cntR[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    words[i] = str;
    toLowerCase(words[i]);
    if (!mid.count(words[i])) {
      mid[words[i]] = N;
      N++;
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%s", str);
    X[i] = str;
    toLowerCase(X[i]);
    if (!mid.count(X[i])) {
      mid[X[i]] = N;
      N++;
    }
    scanf("%s", str);
    Y[i] = str;
    toLowerCase(Y[i]);
    if (!mid.count(Y[i])) {
      mid[Y[i]] = N;
      N++;
    }
  }
  set<pair<pair<int, int>, int> > st;
  for (map<string, int>::iterator it = mid.begin(); it != mid.end(); it++) {
    string tmp = it->first;
    int v = it->second;
    Len[v] = tmp.length();
    cntR[v] = 0;
    for (int i = 0; i < Len[v]; i++) {
      if (tmp[i] == 'r') cntR[v]++;
    }
    st.insert(make_pair(make_pair(cntR[v], Len[v]), v));
  }
  for (int i = 0; i < m; i++) {
    int v = mid[X[i]];
    int u = mid[Y[i]];
    g[u].push_back(v);
  }
  while (!st.empty()) {
    int v = st.begin()->second;
    st.erase(st.begin());
    for (int i = 0; i < ((int)(g[v]).size()); i++) {
      int to = g[v][i];
      if (cntR[v] < cntR[to] || (cntR[v] == cntR[to] && Len[v] < Len[to])) {
        st.erase(make_pair(make_pair(cntR[to], Len[to]), to));
        cntR[to] = cntR[v];
        Len[to] = Len[v];
        st.insert(make_pair(make_pair(cntR[to], Len[to]), to));
      }
    }
  }
  long long ansR = 0, ansL = 0;
  for (int i = 0; i < n; i++) {
    int id = mid[words[i]];
    ansR += cntR[id];
    ansL += Len[id];
  }
  printf("%I64d %I64d\n", ansR, ansL);
  return 0;
}
