#include <bits/stdc++.h>
using namespace std;
struct S {
  vector<int> to;
  int len, rs;
};
int n;
vector<string> words;
int m;
vector<S> g;
map<string, int> convert;
int names = 0;
int visit[int(1e5) + 10];
int update = true;
void go(int v, int step) {
  if (visit[v] == step) return;
  visit[v] = step;
  for (auto to : g[v].to) go(to, step);
  for (auto to : g[v].to) {
    if (g[to].rs < g[v].rs) {
      update = true;
      g[v].rs = g[to].rs;
      g[v].len = g[to].len;
    } else if (g[to].rs == g[v].rs && g[to].len < g[v].len) {
      update = true;
      g[v].len = g[to].len;
    }
  }
}
void tolower(string &s) {
  for (int i = 0; i < s.length(); ++i) s[i] = tolower(s[i]);
}
void task() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  words.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> words[i];
    tolower(words[i]);
  }
  cin >> m;
  g.resize(2 * m);
  for (int i = 0; i < m; ++i) {
    string from, to;
    cin >> from >> to;
    tolower(from);
    tolower(to);
    if (convert.find(from) == convert.end()) {
      convert[from] = names++;
      g[convert[from]].len = from.length();
      g[convert[from]].rs = count(from.begin(), from.end(), 'r');
    }
    if (convert.find(to) == convert.end()) {
      convert[to] = names++;
      g[convert[to]].len = to.length();
      g[convert[to]].rs = count(to.begin(), to.end(), 'r');
    }
    g[convert[from]].to.push_back(convert[to]);
  }
  int step = 1;
  while (update) {
    ++step;
    update = false;
    for (int i = 0; i < names; ++i) go(i, step);
  }
  pair<long long, long long> ans = {0, 0};
  for (auto &s : words)
    if (convert.find(s) != convert.end()) {
      ans.first += g[convert[s]].len;
      ans.second += g[convert[s]].rs;
    } else {
      ans.first += s.length();
      ans.second += count(s.begin(), s.end(), 'r');
    }
  cout << ans.second << ' ' << ans.first;
}
int main() {
  task();
  return 0;
}
