#include <bits/stdc++.h>
using namespace std;
class ti {
 public:
  pair<int, int> d;
  int v;
  ti(pair<int, int> x, int y) { d = x, v = y; }
};
map<string, int> dict;
int w[100001];
string inv[100001];
vector<vector<int> > e(100001);
queue<ti> q;
pair<int, int> dist[100001];
string l_case(string second) {
  int ds = second.size();
  for (int i = 0; i < ds; i++) {
    if (second[i] < 'a') second[i] = (char)(second[i] + 'a' - 'A');
  }
  return second;
}
int idx(string second) {
  second = l_case(second);
  if (dict.find(second) != dict.end()) return dict[second];
  int d = dict.size();
  dict[second] = d;
  inv[d] = second;
  return d;
}
int upd() {
  string second;
  cin >> second;
  int tp = idx(second);
  return tp;
}
pair<int, int> val(string second) {
  pair<int, int> r;
  r.first = 0, r.second = second.size();
  for (int i = 0; i < r.second; i++) r.first += (second[i] == 'r');
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) w[i] = upd();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a = upd();
    int b = upd();
    e[b].push_back(a);
  }
  int d = dict.size();
  for (int i = 0; i < d; i++) {
    dist[i] = val(inv[i]);
    q.push(ti(dist[i], i));
  }
  while (!q.empty()) {
    int v = q.front().v;
    pair<int, int> d = q.front().d;
    q.pop();
    if (d > dist[v]) continue;
    int de = e[v].size();
    for (int i = 0; i < de; i++) {
      int nv = e[v][i];
      if (d < dist[nv]) {
        dist[nv] = d;
        q.push(ti(dist[nv], nv));
      }
    }
  }
  long long cn1 = 0, cn2 = 0;
  for (int i = 0; i < m; i++) {
    cn1 += dist[w[i]].first;
    cn2 += dist[w[i]].second;
  }
  cout << cn1 << " " << cn2 << "\n";
  return 0;
}
