#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, int> Ind;
int cnt = 0;
pair<int, int> val[312345];
int get_id(string s) {
  int res, rsum = 0, len = s.size();
  for (int i = 0; i < len; i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
    if (s[i] == 'r') ++rsum;
  }
  if (res = Ind[s])
    return res;
  else
    res = ++cnt;
  Ind[s] = cnt;
  val[cnt] = make_pair(rsum, len);
  return res;
}
int tot;
int head[312345];
struct edge {
  int to, next;
} e[312345];
void insert(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
  return;
}
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
               greater<pair<pair<int, int>, int> > >
    q;
bool vis[312345];
void Go() {
  while (!q.empty()) q.pop();
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= cnt; i++) q.push(make_pair(val[i], i));
  while (!q.empty()) {
    int x = q.top().second;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = head[x]; i; i = e[i].next) {
      int y = e[i].to;
      if (val[x] < val[y]) {
        val[y] = val[x];
        q.push(make_pair(val[y], y));
      }
    }
  }
  return;
}
int a[312345];
int main() {
  string s, t;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    a[i] = get_id(s);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    cin >> s;
    cin >> t;
    int x = get_id(s), y = get_id(t);
    insert(y, x);
  }
  Go();
  long long rsum = 0, len = 0;
  for (int i = 1; i <= n; i++) {
    rsum += val[a[i]].first;
    len += val[a[i]].second;
  }
  printf("%I64d %I64d\n", rsum, len);
  return 0;
}
