#include <bits/stdc++.h>
using namespace std;
bool Comp(const pair<int, string>& a, const pair<int, string>& b) {
  if (a.first != b.first) return (a.first > b.first);
  return (a.second < b.second);
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, string> > VN(n);
  for (int i = 0; i < n; i++) cin >> VN[i].second >> VN[i].first;
  int m;
  cin >> m;
  vector<int> VM(n);
  for (int i = 0; i < m; i++) cin >> VM[i];
  string nick;
  cin >> nick;
  sort(VN.begin(), VN.end(), Comp);
  {
    vector<pair<int, string> > tmp(VN);
    sort(VM.begin(), VM.end(), greater<int>());
    for (vector<pair<int, string> >::iterator it = tmp.begin(); it != tmp.end();
         it++)
      if ((*it).second == nick) {
        reverse(tmp.begin(), it);
        rotate(tmp.begin(), it, tmp.end());
        break;
      }
    for (int i = 0; i < n; i++) tmp[i].first += VM[i];
    sort(tmp.begin(), tmp.end(), Comp);
    for (int i = 0; i < n; i++)
      if (tmp[i].second == nick) {
        cout << i + 1;
        break;
      }
  }
  cout << " ";
  {
    vector<pair<int, string> > tmp(VN);
    sort(VM.begin(), VM.end());
    pair<int, string> cmp;
    int res = 1;
    for (vector<pair<int, string> >::iterator it = tmp.begin(); it != tmp.end();
         it++, res++)
      if ((*it).second == nick) {
        cmp = (*it);
        tmp.erase(tmp.begin(), ++it);
        break;
      }
    cmp.first += VM[0];
    for (int i = res, j = 0; i < n && j < tmp.size(); i++) {
      pair<int, string> newcmp = tmp[j];
      newcmp.first += VM[i];
      if (!Comp(cmp, newcmp)) {
        res++;
        j++;
      }
    }
    cout << res;
  }
exit:
  return (0);
}
