#include <bits/stdc++.h>
using namespace std;
struct cmp {
  bool operator()(const pair<int, string>& p1,
                  const pair<int, string>& p2) const {
    if (p1.first != p2.first) return p1.first > p2.first;
    return p1.second < p2.second;
  }
};
int n, m;
vector<pair<int, string> > v;
vector<int> ms;
int best(int score, string name) {
  vector<pair<int, string> > vv = v;
  vector<int> ms = ::ms;
  sort(vv.begin(), vv.end(), cmp());
  if (ms.size() >= 1) {
    score += ms[0];
    ms.erase(ms.begin());
  }
  for (int i = 0; i < ms.size(); i++) vv[vv.size() - i - 1].first += ms[i];
  sort(vv.begin(), vv.end(), cmp());
  return upper_bound(vv.begin(), vv.end(), make_pair(score, name), cmp()) -
         vv.begin() + 1;
}
int worst(int score, string name) {
  vector<pair<int, string> > vv = v;
  vector<int> ms = ::ms;
  sort(vv.begin(), vv.end(), cmp());
  if (ms.size() == n) {
    score += ms.back();
    ms.erase(ms.end() - 1);
  }
  int j = upper_bound(vv.begin(), vv.end(), make_pair(score, name), cmp()) -
          vv.begin();
  cmp c;
  for (int i = ms.size() - 1; i >= 0 && j < vv.size(); i--)
    if (c(make_pair(vv[j].first + ms[i], vv[j].second), make_pair(score, name)))
      vv[j].first += ms[i], j++;
  sort(vv.begin(), vv.end(), cmp());
  return upper_bound(vv.begin(), vv.end(), make_pair(score, name), cmp()) -
         vv.begin() + 1;
}
int main() {
  cin >> n;
  if (cin.fail()) return 0;
  v.resize(n);
  for (int i = 0; i < n; i++) cin >> v[i].second >> v[i].first;
  cin >> m;
  ms.resize(m);
  for (int i = 0; i < m; i++) cin >> ms[i];
  string name;
  cin >> name;
  int score;
  for (int i = 0; i < v.size(); i++)
    if (v[i].second == name) {
      score = v[i].first;
      v.erase(v.begin() + i);
      break;
    }
  sort(ms.begin(), ms.end(), greater<int>());
  cout << best(score, name) << " " << worst(score, name) << endl;
  return 0;
}
