#include <bits/stdc++.h>
using namespace std;
long long n, m, id, x, y, ans, ans2, idx[100100];
pair<long long, long long> arr[100100];
string s[100100], a, b;
map<string, long long> mep;
vector<long long> graph[100100];
vector<pair<pair<long long, long long>, long long> > vec;
bool vis[100100];
bool cmp(pair<pair<long long, long long>, int> a,
         pair<pair<long long, long long>, int> b) {
  if (a.first.first == b.first.first) return a.first.second < b.first.second;
  return a.first.first < b.first.first;
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < graph[u].size(); i++) {
    int v = graph[u][i];
    if (!vis[v]) {
      idx[v] = idx[u];
      dfs(v);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i].size(); j++) s[i][j] = tolower(s[i][j]);
    if (mep.find(s[i]) == mep.end()) {
      mep[s[i]] = id;
      int temp = 0;
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == 'r' || s[i][j] == 'R') temp++;
      }
      arr[id] = make_pair(temp, s[i].size());
      vec.push_back(make_pair(make_pair(arr[id].first, arr[id].second), id));
      id++;
    }
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    for (int j = 0; j < a.size(); j++) a[j] = tolower(a[j]);
    for (int j = 0; j < b.size(); j++) b[j] = tolower(b[j]);
    if (mep.find(a) == mep.end()) {
      mep[a] = id;
      int temp = 0;
      for (int i = 0; i < a.size(); i++) {
        if (a[i] == 'r' || a[i] == 'R') temp++;
      }
      arr[id] = make_pair(temp, a.size());
      vec.push_back(make_pair(make_pair(arr[id].first, arr[id].second), id));
      id++;
    }
    if (mep.find(b) == mep.end()) {
      mep[b] = id;
      int temp = 0;
      for (int i = 0; i < b.size(); i++) {
        if (b[i] == 'r' || b[i] == 'R') temp++;
      }
      arr[id] = make_pair(temp, b.size());
      vec.push_back(make_pair(make_pair(arr[id].first, arr[id].second), id));
      id++;
    }
    x = mep[a];
    y = mep[b];
    graph[y].push_back(x);
  }
  for (int i = 0; i < n; i++) idx[i] = i;
  sort(vec.begin(), vec.end(), cmp);
  for (int i = 0; i < vec.size(); i++) {
    x = vec[i].second;
    if (!vis[x]) {
      idx[x] = x;
      dfs(x);
    }
  }
  for (int i = 0; i < n; i++) {
    x = mep[s[i]];
    y = idx[x];
    ans += arr[y].first;
    ans2 += arr[y].second;
  }
  cout << ans << " " << ans2 << endl;
  return 0;
}
