#include <bits/stdc++.h>
using namespace std;
map<string, list<string>> mp;
map<string, pair<int, int>> dp;
string tolowStr(string& s) {
  string ts = s;
  for (auto& c : ts) {
    c = tolower(c);
  }
  return ts;
}
int getR(string& s) {
  int cnt = 0;
  for (auto& c : s) {
    if (c == 'r') {
      ++cnt;
    }
  }
  return cnt;
}
bool operator<(pair<int, int>& a, pair<int, int>& b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
pair<int, int> found(string s) {
  if (dp.find(s) != dp.end()) {
    return dp[s];
  }
  dp[s] = make_pair(getR(s), s.length());
  for (string& ts : mp[s]) {
    dp[s] = min(dp[s], found(ts));
  }
  return dp[s];
}
void setMin(string s, int cnt, int len, set<string>& st) {
  if (st.find(s) != st.end()) {
    return;
  } else {
    st.insert(s);
  }
  dp[s] = make_pair(cnt, len);
  for (string& ts : mp[s]) {
    setMin(ts, cnt, len, st);
  }
}
int main() {
  int n;
  cin >> n;
  vector<string> v;
  multimap<pair<int, int>, string> rmp;
  for (int i = 1; i <= n; ++i) {
    string ts;
    cin >> ts;
    ts = tolowStr(ts);
    v.push_back(ts);
    rmp.insert(make_pair(make_pair(getR(ts), ts.length()), ts));
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    s1 = tolowStr(s1);
    s2 = tolowStr(s2);
    mp[s2].push_back(s1);
    rmp.insert(make_pair(make_pair(getR(s2), s2.length()), s2));
  }
  set<string> st;
  for (auto& p : rmp) {
    setMin(p.second, p.first.first, p.first.second, st);
  }
  long long int cnt = 0, len = 0;
  for (string& s : v) {
    if (mp.find(s) != mp.end()) {
      cnt += dp[s].first;
      len += dp[s].second;
    } else {
      cnt += getR(s);
      len += s.length();
    }
  }
  cout << cnt << " " << len << endl;
  return 0;
}
