#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
const int N = 3e5 + 7;
const int M = -1;
map<string, int> g;
vector<pair<int, int> > z;
vector<int> e[N];
int no, p[N], rd[N];
int id(string x) {
  for (int i = 0; i < (x.length()); ++i)
    if (x[i] >= 'A' && x[i] <= 'Z') x[i] = x[i] - 'A' + 'a';
  if (g.find(x) != g.end()) return g[x];
  g[x] = no;
  int t = 0;
  for (int i = 0; i < (x.length()); ++i) {
    if (x[i] == 'r' || x[i] == 'R') t++;
  }
  z.push_back(make_pair(-t, -x.length()));
  return no++;
}
int done[N];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    string t;
    cin >> t;
    p[i] = id(t);
  }
  vector<pair<pair<int, int>, int> > Q;
  int m;
  cin >> m;
  for (int i = 0; i < (m); ++i) {
    string u, v;
    cin >> u >> v;
    int t = id(u), s = id(v);
    e[s].push_back(t);
    Q.push_back(make_pair(z[s], s));
  }
  sort((Q).begin(), (Q).end());
  while (!Q.empty()) {
    int u = Q.back().second;
    Q.pop_back();
    if (done[u]) continue;
    done[u] = 1;
    for (int v : e[u]) {
      if (z[v].first < z[u].first ||
          z[v].first == z[u].first && z[v].second < z[u].second) {
        z[v] = z[u];
        Q.push_back(make_pair(z[v], v));
      }
    }
  }
  long long ans1 = 0, ans2 = 0;
  for (int i = 0; i < (n); ++i) {
    ans1 -= z[p[i]].first;
    ans2 -= z[p[i]].second;
  }
  cout << ans1 << ' ' << ans2 << endl;
  return 0;
}
