#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inf2 = (1 << 62) - 1;
const double eps = 1e-6;
vector<string> v;
map<string, pair<int, int> > mp;
map<string, vector<string> > g;
vector<string> dat;
set<string> vis;
pair<int, int> getpair(string s) {
  if (mp.find(s) != mp.end()) return mp[s];
  int rs = 0;
  for (int i = 0; i < s.size(); i++) rs += (s[i] == 'r');
  return mp[s] = make_pair(rs, s.size());
}
void tolower(string &s1) {
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] >= 'A' && s1[i] <= 'Z') s1[i] = s1[i] - 'A' + 'a';
  }
}
void dfs(string x, pair<int, int> data) {
  vis.insert(x);
  for (int i = 0; i < g[x].size(); i++) {
    if (mp[g[x][i]] > data) {
      vis.insert(g[x][i]);
      mp[g[x][i]] = data;
      dfs(g[x][i], data);
    }
  }
}
bool cmp(string a, string b) { return mp[a] < mp[b]; }
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  while (n--) {
    string s;
    cin >> s;
    tolower(s);
    cnt++;
    dat.push_back(s);
    getpair(s);
    v.push_back(s);
  }
  int k;
  cin >> k;
  while (k--) {
    string s1, s2;
    cin >> s1 >> s2;
    tolower(s1);
    tolower(s2);
    getpair(s1);
    getpair(s2);
    v.push_back(s1);
    v.push_back(s2);
    g[s2].push_back(s1);
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < v.size(); i++)
    if (vis.count(v[i]) == 0) dfs(v[i], mp[v[i]]);
  long long ans1 = 0, ans2 = 0;
  for (int i = 0; i < dat.size(); i++) {
    ans1 += mp[dat[i]].first;
    ans2 += mp[dat[i]].second;
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
