#include <bits/stdc++.h>
using namespace std;
const int MaxA = 1e5 + 3;
const int MaxB = 1e4 + 3;
const int MaxStateNum = 1e5 + 3;
const double eps = 1e-9;
const double pi = atan(1.0) * 4.0;
const int INF = 1e7;
const int MemsetBigNum = 127;
const int MemsetSmallNum = 9856;
int n, m, wordNum;
vector<int> essay;
vector<int> G[MaxA];
map<string, int> lib;
pair<int, int> r[MaxA];
priority_queue<pair<pair<int, int>, int> > Q;
bool vis[MaxA];
int getInd(string s) {
  string t;
  for (int i = 0; s[i]; i++)
    if (s[i] >= 'A' && s[i] <= 'Z')
      t.push_back(s[i] - 'A' + 'a');
    else
      t.push_back(s[i]);
  if (lib[t]) return lib[t];
  lib[t] = ++wordNum;
  int cnt = 0;
  for (int i = 0; t[i]; i++)
    if (t[i] == 'r') cnt++;
  r[lib[t]] = make_pair(-cnt, -t.size());
  Q.push(make_pair(make_pair(-cnt, -t.size()), lib[t]));
  return lib[t];
}
int main() {
  ios::sync_with_stdio(false);
  cin >> m;
  wordNum = 0;
  for (int i = 0; i < m; i++) {
    string str;
    cin >> str;
    essay.push_back(getInd(str));
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    string sa, sb;
    cin >> sa >> sb;
    int a = getInd(sa), b = getInd(sb);
    G[b].push_back(a);
  }
  memset(vis, false, sizeof(vis));
  while (!Q.empty()) {
    int u = Q.top().second;
    Q.pop();
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
      int &v = G[u][i];
      if (r[u] > r[v]) {
        r[v] = r[u];
        Q.push(make_pair(r[v], v));
      }
    }
  }
  long long ansA = 0, ansB = 0;
  for (int i = 0; i < essay.size(); i++) {
    ansA -= r[essay[i]].first;
    ansB -= r[essay[i]].second;
  }
  cout << ansA << " " << ansB << endl;
  return 0;
}
