#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
int m, n;
char buf[1 << 20];
map<long long, int> M;
int ID(long long x) {
  if (M[x] == 0) M[x] = M.size();
  return M[x] - 1;
}
int N = 0;
long long R[1 << 20];
long long L[1 << 20];
long long Hash(char* s) {
  long long h1 = 0, h2 = 0;
  int MOD = (int)1e9 + 9;
  for (int i = 0; s[i]; ++i) {
    char c = ('A' <= s[i] && s[i] <= 'Z') ? s[i] + 'a' - 'A' : s[i];
    h1 = (h1 * 2999 + c) % MOD;
    h2 = (h2 * 47 + c) % MOD;
  }
  return h1 * MOD + h2;
}
int getr(char* s) {
  int r = 0;
  for (int j = 0; buf[j]; ++j) r += buf[j] == 'r' || buf[j] == 'R';
  return r;
}
long long cnt[1 << 20];
vector<int> G[1 << 20];
vector<int> Gt[1 << 20];
vector<int> order;
int used[1 << 20];
long long cr[1 << 20];
long long clen[1 << 20];
long long cc[1 << 20];
vector<int> C[1 << 20];
void dfs1(int x) {
  if (used[x]) return;
  used[x] = 1;
  for (int i = 0; i < G[x].size(); ++i) dfs1(G[x][i]);
  order.push_back(x);
}
void dfs2(int x, int c) {
  cr[c] = min(cr[c], R[x]);
  clen[c] = min(clen[c], L[x]);
  cc[x] = c;
  used[x] = 1;
  for (int i = 0; i < Gt[x].size(); ++i) {
    int to = Gt[x][i];
    if (used[to]) continue;
    dfs2(to, c);
  }
}
long long newr[1 << 20];
long long newlen[1 << 20];
void go(int x) {
  if (newr[x] != -1) return;
  newr[x] = cr[x];
  newlen[x] = clen[x];
  for (int i = 0; i < C[x].size(); ++i) {
    go(C[x][i]);
    if (newr[x] == newr[C[x][i]]) newlen[x] = min(newlen[x], newlen[C[x][i]]);
    if (newr[x] > newr[C[x][i]]) {
      newr[x] = newr[C[x][i]];
      newlen[x] = newlen[C[x][i]];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", buf);
    int id = ID(Hash(buf));
    cnt[id]++;
    R[id] = getr(buf);
    L[id] = strlen(buf);
  }
  N = M.size();
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%s", buf);
    int u = ID(Hash(buf));
    R[u] = getr(buf);
    L[u] = strlen(buf);
    scanf("%s", buf);
    int v = ID(Hash(buf));
    R[v] = getr(buf);
    L[v] = strlen(buf);
    G[u].push_back(v);
    Gt[v].push_back(u);
  }
  memset(used, 0, sizeof(used));
  for (int i = 0; i < M.size(); ++i) dfs1(i);
  reverse(order.begin(), order.end());
  memset(used, 0, sizeof(used));
  int c = 0;
  for (int i = 0; i < order.size(); ++i)
    if (!used[order[i]]) {
      cr[c] = (int)1e9;
      clen[c] = (int)1e9;
      dfs2(order[i], c++);
    }
  for (int i = 0; i < M.size(); ++i)
    for (int j = 0; j < G[i].size(); ++j)
      if (cc[i] != cc[G[i][j]]) C[cc[i]].push_back(cc[G[i][j]]);
  memset(newr, -1, sizeof(newr));
  memset(newlen, -1, sizeof(newlen));
  for (int i = 0; i < c; ++i) go(i);
  long long A = 0, B = 0;
  for (int i = 0; i < N; ++i) {
    A += cnt[i] * newr[cc[i]];
    B += cnt[i] * newlen[cc[i]];
  }
  printf("%I64d %I64d\n", A, B);
  return 0;
}
