#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
const int N = 1e5 + 5;
long long m, n;
string a[N];
int equivalent[N];
map<string, long long> m1;
long long k = 1;
vector<long long> g[N];
int val[2 * N];
string storeval[2 * N];
int vis[2 * N];
struct node {
  int count_r = 0;
  int len = 0;
  int val;
};
node store[2 * N];
int tosort[2 * N];
void lowercase(string &s) {
  long long sz = s.size();
  for (long long i = 0; i < sz; i++) {
    s[i] = tolower(s[i]);
  }
}
int assign(string &s) {
  if (m1.find(s) == m1.end()) {
    storeval[k] = s;
    m1[s] = k++;
  }
  return m1[s];
}
node function1(string &s) {
  node nd;
  int sz = s.size();
  for (int i = 0; i < sz; i++) {
    if (s[i] == 'r') {
      nd.count_r++;
    }
  }
  nd.len = sz;
  nd.val = m1[s];
  return nd;
}
bool comp(int &a, int &b) {
  if (store[a].count_r < store[b].count_r) {
    return true;
  } else if (store[a].count_r == store[b].count_r) {
    return store[a].len < store[b].len;
  } else {
    return false;
  }
}
void dfs(int i, int parentval) {
  if (vis[i]) return;
  vis[i] = 1;
  val[i] = val[parentval];
  for (auto it : g[i]) {
    dfs(it, i);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    cin >> a[i];
    lowercase(a[i]);
    equivalent[i] = assign(a[i]);
  }
  for (long long i = 0; i < 2 * N; i++) {
    val[i] = i;
  }
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    lowercase(x);
    lowercase(y);
    int xeq = assign(x);
    int yeq = assign(y);
    g[yeq].push_back(xeq);
  }
  int ind = 1;
  for (auto it : m1) {
    string cur = it.first;
    node n1 = function1(cur);
    store[it.second] = n1;
    ind++;
  }
  for (long long i = 1; i < ind; i++) {
    tosort[i] = i;
  }
  sort(tosort, tosort + ind, comp);
  for (long long i = 0; i < ind; i++) {
    if (!vis[tosort[i]]) {
      dfs(tosort[i], tosort[i]);
    }
  }
  long long ans1 = 0;
  long long ans2 = 0;
  for (long long i = 0; i < m; i++) {
    int originalvalue = m1[a[i]];
    int newval = val[originalvalue];
    ans1 += store[newval].count_r;
    ans2 += store[newval].len;
  }
  cout << ans1 << " " << ans2;
  return 0;
}
