#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
string rev[300001];
vector<int> path[100001];
map<string, int> rec;
int n, m, r[100001], l[100001];
pair<pair<int, int>, int> h[100001];
string a[100001];
string x, y;
char c;
long long ansr, ansl;
int tot, now;
bool vis[100001];
void add(string p) {
  if (rec.find(p) == rec.end()) {
    tot++;
    rec[p] = tot;
    rev[tot] = p;
    l[tot] = p.length();
    r[tot] = 0;
    for (int i = 0; i < p.length(); i++)
      if (p[i] == 'R') r[tot]++;
  }
  return;
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first != b.first.first)
    return a.first.first > b.first.first;
  else if (a.first.second != b.first.second)
    return a.first.second > b.first.second;
  else
    return a.second > b.second;
}
int main() {
  scanf("%d\n", &m);
  for (int i = 1; i <= m; i++) {
    c = getchar();
    a[i] = "";
    while (c != ' ' && c != '\n') {
      if (c >= 'a') c = c - 'a' + 'A';
      a[i] += c;
      c = getchar();
    }
    add(a[i]);
  }
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) {
    c = getchar();
    x = "";
    while (c != ' ' && c != '\n') {
      if (c >= 'a') c = c - 'a' + 'A';
      x += c;
      c = getchar();
    }
    c = getchar();
    y = "";
    while (c != ' ' && c != '\n') {
      if (c >= 'a') c = c - 'a' + 'A';
      y += c;
      c = getchar();
    }
    add(x);
    add(y);
    path[rec[y]].push_back(rec[x]);
  }
  for (int i = 1; i <= tot; i++) {
    vis[i] = false;
    h[i] = make_pair(make_pair(r[i], l[i]), i);
  }
  now = tot;
  make_heap(h + 1, h + now + 1, cmp);
  for (int i = 1; i < tot; i++) {
    pop_heap(h + 1, h + now + 1, cmp);
    now--;
    while (vis[h[now + 1].second]) {
      pop_heap(h + 1, h + now + 1, cmp);
      now--;
    }
    pair<pair<int, int>, int> temp = h[now + 1];
    vis[temp.second] = true;
    for (int j = 0; j < path[temp.second].size(); j++) {
      int temp1 = path[temp.second][j];
      if (temp.first.first < r[temp1] ||
          temp.first.first == r[temp1] && temp.first.second < l[temp1]) {
        r[temp1] = temp.first.first;
        l[temp1] = temp.first.second;
        now++;
        h[now] = make_pair(make_pair(r[temp1], l[temp1]), temp1);
        push_heap(h + 1, h + now + 1, cmp);
      }
    }
  }
  ansr = ansl = 0;
  for (int i = 1; i <= m; i++) {
    int temp = rec[a[i]];
    ansr += r[temp];
    ansl += l[temp];
  }
  printf("%I64d %I64d\n", ansr, ansl);
  return 0;
}
