#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100500;
vector<int> G[MAXN];
map<string, int> num;
vector<string> essey;
int table[MAXN][2];
int ess[MAXN][2];
bool visited[MAXN];
struct triple {
  int r;
  int len;
  int node;
  triple(int a, int b, int c) {
    r = a;
    len = b;
    node = c;
  }
};
bool comp(triple a, triple b) {
  return ((a.r < b.r) || (a.r == b.r && a.len < b.len));
}
void enter1(string s, int p) {
  int br = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'r' || s[i] == 'R') br++;
  ess[p][0] = br;
  ess[p][1] = s.size();
}
void enter(string s, int u) {
  int br = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'r' || s[i] == 'R') br++;
  table[u][0] = br;
  table[u][1] = s.size();
}
void dfs(int curr, int r, int len) {
  visited[curr] = true;
  table[curr][0] = r;
  table[curr][1] = len;
  for (auto v : G[curr])
    if (!visited[v]) dfs(v, r, len);
}
void pass(int N) {
  vector<triple> v;
  for (int i = 1; i < N; i++) v.push_back(triple(table[i][0], table[i][1], i));
  sort(v.begin(), v.end(), comp);
  for (int i = 0; i < v.size(); i++)
    if (!visited[v[i].node]) dfs(v[i].node, v[i].r, v[i].len);
}
int main() {
  int M, N, cnt = 1;
  string s, x, y;
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++) s[j] = tolower(s[j]);
    enter1(s, i);
    essey.push_back(s);
  }
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    for (int j = 0; j < x.size(); j++) x[j] = tolower(x[j]);
    for (int j = 0; j < y.size(); j++) y[j] = tolower(y[j]);
    if (num[x] == 0) {
      num[x] = cnt;
      enter(x, num[x]);
      cnt++;
    }
    if (num[y] == 0) {
      num[y] = cnt;
      enter(y, num[y]);
      cnt++;
    }
    G[num[y]].push_back(num[x]);
  }
  pass(cnt);
  long long int r = 0, len = 0;
  for (int i = 0; i < M; i++) {
    int p = num[essey[i]];
    if (p == 0) {
      r += ess[i][0];
      len += ess[i][1];
    } else {
      if (table[p][0] < ess[i][0]) {
        r += table[p][0];
        len += table[p][1];
      } else if (table[p][0] == ess[i][0] && table[p][1] < ess[i][1]) {
        r += table[p][0];
        len += table[p][1];
      } else {
        r += ess[i][0];
        len += ess[i][1];
      }
    }
  }
  cout << r << " " << len << endl;
  return 0;
}
