#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 2;
const int MN = 2e5 + 20;
int m, n, nn;
pair<int, long long> ans;
unordered_map<string, int> w;
struct node {
  long long cnt;
  pair<int, int> R_len;
  set<int> fe, re;
};
node v[MN];
void add_string(string second) {
  w[second] = nn;
  int R = 0;
  for (int i = 0; i < second.size(); i++)
    if (second[i] == 'R' || second[i] == 'r') R++;
  v[nn].R_len.first = R;
  v[nn].R_len.second = second.size();
  nn++;
}
int wastopo[MN], wasdfs[MN], wasga[MN];
vector<int> order;
void topo(int to) {
  if (wastopo[to]) return;
  wastopo[to] = 1;
  for (auto it : v[to].fe) topo(it);
  order.push_back(to);
}
void toposort() {
  for (int i = 0; i < nn; i++) topo(i);
}
int link[MN];
pair<int, int> dfs(int root, int to) {
  if (wasdfs[to]) return make_pair(INF, INF);
  wasdfs[to] = 1;
  for (auto it : v[to].re) v[to].R_len = min(v[to].R_len, dfs(root, it));
  for (auto it : v[to].fe) v[root].fe.insert(it);
  if (root != to) v[root].cnt += v[to].cnt;
  link[to] = root;
  return v[to].R_len;
}
string second;
pair<int, int> get_ans(int to) {
  to = link[to];
  if (wasga[to]) return v[to].R_len;
  wasga[to] = 1;
  for (auto it : v[to].fe) v[to].R_len = min(v[to].R_len, get_ans(it));
  ans.first += v[to].R_len.first * v[to].cnt;
  ans.second += v[to].R_len.second * v[to].cnt;
  return v[to].R_len;
}
int main() {
  cin >> m;
  for (int i = 0; i < m; i++) {
    string second;
    cin >> second;
    for (int i = 0; i < second.size(); i++) second[i] = tolower(second[i]);
    if (w.find(second) == w.end()) add_string(second);
    v[w[second]].cnt++;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++) s1[i] = tolower(s1[i]);
    for (int i = 0; i < s2.size(); i++) s2[i] = tolower(s2[i]);
    if (w.find(s1) == w.end()) add_string(s1);
    if (w.find(s2) == w.end()) add_string(s2);
    int fr = w[s1], to = w[s2];
    v[fr].fe.insert(to);
    v[to].re.insert(fr);
  }
  toposort();
  reverse(order.begin(), order.end());
  for (int i : order) dfs(i, i);
  for (int i : order) get_ans(i);
  cout << ans.first << " " << ans.second << endl;
  return 0;
}
