#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 10 * 1000 * 5;
string tolower(string s) {
  for (int i = 0; i < s.size(); ++i) s[i] = tolower(s[i]);
  return s;
}
void push_to_hash(string s, map<string, int> &hash, vector<int> &minR,
                  vector<int> &minL) {
  s = tolower(s);
  if (hash.find(s) == hash.end()) {
    int c = (int)hash.size();
    hash[s] = c;
    int h = hash[s];
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == 'r') {
        minR[h]++;
      }
    }
    minL[h] = s.size();
  }
}
void dfs(int p, const vector<vector<int> > &edges, vector<int> &used,
         vector<int> &minR, vector<int> &minL) {
  if (used[p]) return;
  used[p] = 1;
  for (int i = 0; i < edges[p].size(); ++i) {
    int v = edges[p][i];
    dfs(v, edges, used, minR, minL);
    if (minR[v] < minR[p] || (minR[v] == minR[p] && minL[v] < minL[p])) {
      minR[p] = minR[v];
      minL[p] = minL[v];
    }
  }
}
int main() {
  int m;
  cin >> m;
  map<string, int> hash;
  hash.clear();
  vector<int> minR(MAX_SIZE, 0);
  vector<int> minL(MAX_SIZE, 0);
  vector<string> text(0);
  for (int i = 0; i < m; ++i) {
    string s;
    cin >> s;
    s = tolower(s);
    text.push_back(s);
    push_to_hash(s, hash, minR, minL);
  }
  int n;
  cin >> n;
  vector<vector<int> > edges(MAX_SIZE, vector<int>(0));
  for (int i = 0; i < n; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    s1 = tolower(s1);
    s2 = tolower(s2);
    push_to_hash(s1, hash, minR, minL);
    push_to_hash(s2, hash, minR, minL);
    edges[hash[s1]].push_back(hash[s2]);
  }
  long long resR = 0;
  long long resL = 0;
  vector<int> used0(hash.size(), 0);
  for (int i = 0; i < m; ++i) {
    dfs(hash[text[i]], edges, used0, minR, minL);
  }
  vector<int> used1(hash.size(), 0);
  for (int i = 0; i < m; ++i) {
    int v = hash[text[i]];
    dfs(v, edges, used1, minR, minL);
    resR += minR[v];
    resL += minL[v];
  }
  cout << resR << " " << resL << endl;
  return 0;
}
