#include <bits/stdc++.h>
using namespace std;
const int kN = 100 * 1000;
const int kInf = 1000 * 1000 * 1000;
map<string, int> name2id;
vector<string> id2name;
vector<string> arr;
vector<int> g[kN], gr[kN], graph[kN];
bool used[kN];
vector<int> order, component;
int N;
void DFS1(int u) {
  if (used[u]) {
    return;
  }
  used[u] = true;
  for (int i = 0; i < g[u].size(); ++i) DFS1(g[u][i]);
  order.push_back(u);
}
void DFS2(int u) {
  if (used[u]) {
    return;
  }
  used[u] = true;
  component.push_back(u);
  for (int i = 0; i < gr[u].size(); ++i) DFS2(gr[u][i]);
}
pair<long long, long long> Score(const string& s) {
  int cnt = 0;
  for (int i = 0; i < s.length(); ++i) cnt += s[i] == 'r' ? 1 : 0;
  return make_pair(cnt, s.length());
}
int new_map[kN];
pair<long long, long long> dp[kN];
pair<long long, long long> DP(int u) {
  if (!used[u]) {
    used[u] = true;
    for (int i = 0; i < graph[u].size(); ++i)
      dp[u] = min(dp[u], DP(graph[u][i]));
  }
  return dp[u];
}
void Transform(string& str) {
  for (int i = 0; i < str.length(); ++i) str[i] = tolower(str[i]);
}
void Add(const string& s, const string& t) {
  int from = (int)id2name.size();
  if (name2id.find(s) != name2id.end()) {
    from = name2id[s];
  } else {
    id2name.push_back(s);
    name2id[s] = from;
  }
  int to = (int)id2name.size();
  if (name2id.find(t) != name2id.end()) {
    to = name2id[t];
  } else {
    id2name.push_back(t);
    name2id[t] = to;
  }
  g[from].push_back(to);
  gr[to].push_back(from);
}
int main() {
  int n, m;
  cin >> n;
  arr.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    Transform(arr[i]);
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    string x, y;
    cin >> x >> y;
    Transform(x);
    Transform(y);
    Add(x, y);
  }
  N = (int)id2name.size();
  memset(used, 0, sizeof(used));
  for (int i = 0; i < N; ++i)
    if (!used[i]) {
      DFS1(i);
    }
  memset(used, 0, sizeof(used));
  int id = 0;
  for (int i = 0; i < N; ++i) {
    int u = order[N - i - 1];
    if (!used[u]) {
      DFS2(u);
      dp[id] = {kInf, kInf};
      for (int j = 0; j < component.size(); ++j) {
        new_map[component[j]] = id;
        dp[id] = min(dp[id], Score(id2name[component[j]]));
      }
      component.clear();
      ++id;
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < g[i].size(); ++j)
      graph[new_map[i]].push_back(new_map[g[i][j]]);
  }
  memset(used, 0, sizeof(used));
  long long score = 0, len = 0;
  for (int i = 0; i < arr.size(); ++i) {
    if (name2id.find(arr[i]) == name2id.end()) {
      score += Score(arr[i]).first;
      len += (int)arr[i].length();
    } else {
      int u = name2id[arr[i]];
      int new_u = new_map[u];
      score += DP(new_u).first;
      len += DP(new_u).second;
    }
  }
  cout << score << " " << len;
  return 0;
}
