#include <bits/stdc++.h>
using namespace std;
string para[100001];
int n, m, ti;
map<string, int> ma;
vector<int> neb[200005];
vector<int> neb1[200005];
pair<int, int> data[200005];
int rep[200005], visit[200005], label[200005];
pair<int, int> tim[200005];
set<int> nebl[200005];
string convert(string str) {
  for (int i = 0; i < str.length(); i++) {
    if (str[i] < 96) str[i] = str[i] + 32;
  }
  return str;
}
void dfs(int ind) {
  visit[ind] = 1;
  for (int i = 0; i < neb[ind].size(); i++)
    if (visit[neb[ind][i]] == 0) dfs(neb[ind][i]);
  ti = ti + 1;
  tim[ind].first = ti;
  tim[ind].second = ind;
}
int dfs1(int ind, int lab) {
  visit[ind] = 1;
  label[ind] = lab;
  int crep = ind;
  for (int i = 0; i < neb1[ind].size(); i++) {
    int v = neb1[ind][i];
    if (visit[v] == 0) {
      int x = dfs1(v, lab);
      if (data[x].first < data[crep].first ||
          (data[x].first == data[crep].first &&
           data[x].second < data[crep].second))
        crep = x;
    }
  }
  return crep;
}
int dfs2(int ind) {
  visit[ind] = 1;
  int crep = rep[ind];
  for (std::set<int>::iterator it = nebl[ind].begin(); it != nebl[ind].end();
       ++it) {
    int v = *it;
    int x = dfs2(v);
    if (data[x].first < data[crep].first ||
        (data[x].first == data[crep].first &&
         data[x].second < data[crep].second))
      crep = x;
  }
  rep[ind] = crep;
  return crep;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> para[i];
    para[i] = convert(para[i]);
  }
  cin >> m;
  int ind = 1;
  for (int i = 0; i < m; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    s1 = convert(s1);
    s2 = convert(s2);
    if (ma[s1] == 0) {
      ma[s1] = ind;
      ind++;
      int r = 0;
      for (int j = 0; j < s1.length(); j++)
        if (s1[j] == 'r') r++;
      data[ma[s1]].first = r;
      data[ma[s1]].second = s1.length();
    }
    if (ma[s2] == 0) {
      ma[s2] = ind;
      ind++;
      int r = 0;
      for (int j = 0; j < s2.length(); j++)
        if (s2[j] == 'r') r++;
      data[ma[s2]].first = r;
      data[ma[s2]].second = s2.length();
    }
    neb[ma[s1]].push_back(ma[s2]);
    neb1[ma[s2]].push_back(ma[s1]);
  }
  for (int i = 1; i < ind; i++)
    if (visit[i] == 0) dfs(i);
  sort(tim + 1, tim + ind);
  reverse(tim + 1, tim + ind);
  memset(visit, 0, sizeof(visit));
  int lab = 0;
  for (int i = 1; i < ind; i++) {
    int u = tim[i].second;
    if (visit[u] == 0) {
      rep[lab] = dfs1(u, lab);
      lab++;
    }
  }
  for (int i = 1; i < ind; i++) {
    int clab = label[i];
    for (int j = 0; j < neb[i].size(); j++) {
      int ln = label[neb[i][j]];
      if (clab != ln) {
        nebl[clab].insert(ln);
      }
    }
  }
  memset(visit, 0, sizeof visit);
  for (int i = 0; i < lab; i++) {
    if (visit[i] == 0) {
      dfs2(i);
    }
  }
  long long ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    if (ma[para[i]] != 0) {
      int x = label[ma[para[i]]];
      ans1 = ans1 + (long long)data[rep[x]].first;
      ans2 = ans2 + (long long)data[rep[x]].second;
    } else {
      for (int j = 0; j < para[i].length(); j++)
        if (para[i][j] == 'r') ans1++;
      ans2 = ans2 + (long long)para[i].length();
    }
  }
  cout << ans1 << " " << ans2 << endl;
}
