#include <bits/stdc++.h>
using namespace std;
bool v[100005];
long long n, m, r, len, col, best[100005], a[100005], cnt[100005];
map<string, long long> ind;
map<long long, string> inv;
vector<long long> adj[100005];
vector<string> str;
long long rr(string s) {
  int sum = 0;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'r') sum++;
  return sum;
}
void low(string &s) {
  for (int i = 0; i < s.length(); i++)
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 'a' - 'A';
}
void add(string s) {
  if (ind.find(s) != ind.end()) return;
  ind[s] = col;
  inv[col] = s;
  cnt[col++] = rr(s);
}
bool rule(string a, string b) {
  if (cnt[ind[a]] == cnt[ind[b]]) return a.length() < b.length();
  return cnt[ind[a]] < cnt[ind[b]];
}
void dfs(int a, int b) {
  if (v[a]) return;
  v[a] = true;
  best[a] = b;
  for (int i = 0; i < adj[a].size(); i++) dfs(adj[a][i], b);
}
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    low(s);
    add(s);
    a[i] = ind[s];
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s, t;
    cin >> s >> t;
    low(s);
    low(t);
    add(s);
    add(t);
    adj[ind[t]].push_back(ind[s]);
  }
  for (map<string, long long>::iterator it = ind.begin(); it != ind.end(); it++)
    str.push_back(it->first);
  sort(str.begin(), str.end(), rule);
  for (int i = 0; i < str.size(); i++) dfs(ind[str[i]], ind[str[i]]);
  for (int i = 0; i < m; i++) {
    r += cnt[best[a[i]]];
    len += inv[best[a[i]]].size();
  }
  cout << r << " " << len;
  return 0;
}
