#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
int m, n, a[N], k;
pair<int, int> d[N];
bool dau[N];
map<string, int> Map;
vector<int> ds[N];
priority_queue<pair<pair<int, int>, int> > Q;
int add(string &s) {
  int r = 0;
  for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]), r += s[i] == 'r';
  if (Map[s]) return Map[s];
  Map[s] = ++k;
  d[k] = make_pair(r, s.size());
  Q.push(make_pair(make_pair(-r, -s.size()), k));
  return k;
}
void input() {
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    a[i] = add(s);
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    int u = add(x);
    int v = add(y);
    ds[v].push_back(u);
  }
}
void process() {
  int u, v;
  while (!Q.empty()) {
    u = Q.top().second;
    Q.pop();
    if (dau[u]) continue;
    dau[u] = true;
    for (int i = 0; i < ds[u].size(); i++) {
      v = ds[u][i];
      if (d[v] > d[u]) {
        d[v] = d[u];
        Q.push(make_pair(make_pair(-d[u].first, -d[u].second), v));
      }
    }
  }
  long long r1 = 0, r2 = 0;
  for (int i = 0; i < m; i++) {
    r1 += d[a[i]].first;
    r2 += d[a[i]].second;
  }
  printf("%I64d %I64d\n", r1, r2);
}
int main() {
  input();
  process();
  return 0;
}
