#include <bits/stdc++.h>
using namespace std;
int a[300010 / 3];
int rnum[300010];
int len[300010];
pair<int, int> dp[300010];
vector<int> vec[300010];
int cnt;
map<string, int> ma;
class SCC {
 public:
  void add_edge(int a, int b);
  void init(int num);
  void solve();
  void dfs(int x);
  int low[300010], dis[300010];
  vector<int> g[300010];
  int grp[300010];
  bool inStack[300010];
  stack<int> stk;
  int cnt;
  int n;
} sc;
pair<int, int> f(int x) {
  if (dp[x].first != -1) return dp[x];
  pair<int, int> p, t;
  p = make_pair(rnum[x], len[x]);
  for (int i = 0; i < vec[x].size(); i++) {
    t = f(vec[x][i]);
    if ((t.first < p.first || (t.first == p.first && t.second < p.second)))
      p = t;
  }
  return dp[x] = p;
}
int toInt(string& s) {
  for (int i = 0; i < s.length(); i++) s[i] = tolower(s[i]);
  if (ma.count(s)) return ma[s];
  ma[s] = cnt;
  int k = 0;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'r') k++;
  rnum[cnt] = k;
  len[cnt] = s.length();
  return cnt++;
}
int main() {
  int m, n;
  string s, s2;
  for (int i = 0; i < 300010; i++) dp[i].first = -1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    a[i] = toInt(s);
  }
  cin >> m;
  sc.init(n + 2 * m);
  for (int i = 0; i < m; i++) {
    cin >> s >> s2;
    sc.add_edge(toInt(s), toInt(s2));
  }
  sc.solve();
  for (int i = 0; i < cnt; i++) {
    int g = sc.grp[i];
    if (rnum[i] < rnum[g] || (rnum[i] == rnum[g] && len[i] < len[g])) {
      rnum[g] = rnum[i];
      len[g] = len[i];
    }
  }
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < sc.g[i].size(); j++) {
      int y = sc.g[i][j];
      if (sc.grp[y] != sc.grp[i]) {
        vec[sc.grp[i]].push_back(sc.grp[y]);
      }
    }
  }
  pair<int, long long> sol;
  sol.first = sol.second = 0;
  for (int i = 0; i < n; i++) {
    pair<int, int> p = f(sc.grp[a[i]]);
    sol.first += p.first;
    sol.second += p.second;
  }
  cout << sol.first << ' ' << sol.second << endl;
  return 0;
}
void SCC::add_edge(int a, int b) { g[a].push_back(b); }
void SCC::init(int num) {
  n = num;
  cnt = 0;
  memset(dis, -1, sizeof(dis));
  memset(low, -1, sizeof(low));
  memset(inStack, false, sizeof(inStack));
  for (int i = 0; i < num; i++) g[i].clear();
}
void SCC::solve() {
  for (int i = 0; i < n; i++) {
    if (dis[i] == -1) dfs(i);
  }
}
void SCC::dfs(int x) {
  low[x] = dis[x] = cnt++;
  stk.push(x);
  inStack[x] = true;
  for (int i = 0; i < g[x].size(); i++) {
    int y = g[x][i];
    if (dis[y] == -1) {
      dfs(y);
      low[x] = min(low[x], low[y]);
    } else if (inStack[y]) {
      low[x] = min(low[x], dis[y]);
    }
  }
  if (low[x] == dis[x]) {
    int c;
    do {
      c = stk.top();
      stk.pop();
      inStack[c] = false;
      grp[c] = x;
    } while (c != x);
  }
}
