#include <bits/stdc++.h>
using namespace std;
bool pcmp(pair<string, int> lhs, pair<string, int> rhs) {
  if (lhs.second != rhs.second)
    return lhs.second > rhs.second;
  else
    return lhs.first < lhs.first;
}
int main() {
  int n;
  while (cin >> n) {
    vector<pair<string, int> > players;
    for (int i = 0; i < n; ++i) {
      string name;
      int score;
      cin >> name >> score;
      players.push_back(make_pair(name, score));
    }
    sort(players.begin(), players.end(), pcmp);
    int m, d[100005];
    cin >> m;
    memset(d, 0, sizeof(d));
    for (int i = 0; i < m; ++i) {
      cin >> d[i];
    }
    string myname;
    int mys;
    cin >> myname;
    for (int i = 0; i < players.size(); ++i)
      if (players[i].first == myname) {
        mys = players[i].second;
        break;
      }
    multiset<int> ms(d, d + n);
    vector<pair<string, int> >::iterator it;
    multiset<int>::iterator sit;
    int mymin = *(ms.begin()) + mys;
    ms.erase(ms.begin());
    int minr = 1, maxr = 1;
    for (it = players.begin(); it != players.end(); ++it) {
      if (it->first == myname) continue;
      if (it->first < myname) {
        sit = ms.lower_bound(mymin - it->second);
      } else {
        sit = ms.upper_bound(mymin - it->second);
      }
      if (sit == ms.end()) {
        sit = ms.begin();
      } else {
        ++maxr;
      }
      ms.erase(sit);
    }
    multiset<int> ss(d, d + n);
    sit = ss.end();
    --sit;
    int mymax = *sit + mys;
    ss.erase(sit);
    reverse(players.begin(), players.end());
    vector<pair<string, int> >::reverse_iterator rit;
    for (rit = players.rbegin(); rit != players.rend(); ++rit) {
      if (rit->first == myname) continue;
      if (rit->first < myname) {
        sit = ss.lower_bound(mymax - rit->second);
      } else {
        sit = ss.upper_bound(mymax - rit->second);
      }
      if (sit == ss.begin()) {
        sit = ss.end();
        --sit;
        ++minr;
      } else {
        --sit;
      }
      ss.erase(sit);
    }
    printf("%d %d\n", minr, maxr);
  }
  return 0;
}
