#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
map<string, long long> mp;
long long bh, n, m, yu[N];
vector<int> vec[N];
string cat, tac;
long long ans, length;
bool vis[N];
pair<long long, long long> cnt[N];
priority_queue<pair<pair<long long, long long>, long long> > pq;
int getd(string &p) {
  int le = p.size();
  int c = 0;
  for (int i = 0; i < le; i++) {
    if (p[i] >= 'A' && p[i] <= 'Z') p[i] = p[i] + 'a' - 'A';
    if (p[i] == 'r') c++;
  }
  if (mp.find(p) != mp.end()) return mp[p];
  mp[p] = ++bh;
  cnt[mp[p]] = make_pair(-c, -le);
  pq.push(make_pair(cnt[mp[p]], mp[p]));
  return mp[p];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> cat;
    yu[i] = getd(cat);
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> cat >> tac;
    vec[getd(tac)].push_back(getd(cat));
  }
  while (!pq.empty()) {
    int a = pq.top().second;
    pq.pop();
    if (vis[a]) continue;
    vis[a] = true;
    for (int i = 0; i < vec[a].size(); i++) {
      if (cnt[vec[a][i]] < cnt[a]) {
        cnt[vec[a][i]] = cnt[a];
        pq.push(make_pair(cnt[vec[a][i]], vec[a][i]));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += -cnt[yu[i]].first;
    length += -cnt[yu[i]].second;
  }
  cout << ans << " " << length << endl;
  return 0;
}
