#include <bits/stdc++.h>
using namespace std;
void lowercase(char *c) {
  while (*c) {
    if ('A' <= *c && *c <= 'Z') *c = *c + 'a' - 'A';
    ++c;
  }
}
pair<int, int> weight(string &s) {
  int size = 0, nb_r = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'r') ++nb_r;
    ++size;
  }
  return make_pair(nb_r, size);
}
map<string, int> nodes;
map<int, pair<int, int> > res;
vector<int> rev_edges[100001];
void walk(int node, int nb_r, int size) {
  if (res.find(node) != res.end()) return;
  res[node] = make_pair(nb_r, size);
  for (auto it = rev_edges[node].begin(); it != rev_edges[node].end(); ++it) {
    walk(*it, nb_r, size);
  }
}
int main(int argc, char *argv[]) {
  int n;
  scanf("%d ", &n);
  char word[500001];
  vector<string> essay;
  for (int i = 0; i < n; ++i) {
    scanf("%s ", word);
    lowercase(word);
    essay.push_back(string(word));
  }
  scanf("%d ", &n);
  vector<pair<pair<int, int>, int> > wv;
  int nb_nodes = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%s ", word);
    lowercase(word);
    string s = string(word);
    int from, to;
    auto it = nodes.find(s);
    if (it != nodes.end())
      from = it->second;
    else {
      from = nb_nodes++;
      nodes[s] = from;
      wv.push_back(make_pair(weight(s), from));
    }
    scanf("%s ", word);
    lowercase(word);
    s = string(word);
    it = nodes.find(s);
    if (it != nodes.end())
      to = it->second;
    else {
      to = nb_nodes++;
      nodes[s] = to;
      wv.push_back(make_pair(weight(s), to));
    }
    rev_edges[to].push_back(from);
  }
  sort(wv.begin(), wv.end());
  for (auto it = wv.begin(); it != wv.end(); ++it) {
    int nb_r = it->first.first;
    int size = it->first.second;
    walk(it->second, nb_r, size);
  }
  long long int size = 0, nb_r = 0;
  for (auto it = essay.begin(); it != essay.end(); ++it) {
    auto w = nodes.find(*it);
    if (w != nodes.end()) {
      nb_r += res[w->second].first;
      size += res[w->second].second;
    } else {
      pair<int, int> p = weight(*it);
      nb_r += p.first;
      size += p.second;
    }
  }
  cout << nb_r << " " << size << endl;
  return 0;
}
