#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, m, len = 0, a[100010], sn, tn, ans = 0, ans2 = 0;
bool vis[300010];
pair<long long, long long> best[300010];
vector<long long> g[300010], pass;
map<string, long long> mp;
string s, t;
set<pair<pair<long long, long long>, long long> > q;
inline void upd(long long num, string p) {
  best[num].second = p.size();
  for (int i = 0; i < best[num].second; i++)
    if (p[i] == 'R' || p[i] == 'r') best[num].first++;
}
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++)
      if (isupper(s[j])) s[j] += 'a' - 'A';
    if (mp[s] != 0)
      a[i] = mp[s];
    else {
      mp[s] = ++len;
      a[i] = len;
      upd(a[i], s);
      q.insert({{best[len].first, best[len].second}, len});
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    for (int j = 0; j < s.size(); j++)
      if (isupper(s[j])) s[j] += 'a' - 'A';
    for (int j = 0; j < t.size(); j++)
      if (isupper(t[j])) t[j] += 'a' - 'A';
    if (mp[s] != 0)
      sn = mp[s];
    else {
      mp[s] = ++len;
      sn = len;
      upd(len, s);
      q.insert({{best[len].first, best[len].second}, len});
    }
    if (mp[t] != 0)
      tn = mp[t];
    else {
      mp[t] = ++len;
      tn = len;
      upd(len, t);
      q.insert({{best[len].first, best[len].second}, len});
    }
    g[tn].push_back(sn);
  }
  while (q.size() > 0) {
    pair<pair<long long, long long>, long long> t = *q.begin();
    q.erase(q.begin());
    long long pos = t.second;
    if (best[pos] < t.first) continue;
    for (int i = 0; i < g[pos].size(); i++) {
      if (best[g[pos][i]] <= t.first) continue;
      best[g[pos][i]] = t.first;
      q.insert({best[g[pos][i]], g[pos][i]});
    }
  }
  for (int i = 0; i < m; i++) {
    ans += best[a[i]].first;
    ans2 += best[a[i]].second;
  }
  cout << ans << ' ' << ans2 << endl;
  return 0;
}
