#include <bits/stdc++.h>
using namespace std;
inline double sqr(double x) { return x * x; }
bool cmp(const pair<string, int>& a, const pair<string, int>& b) {
  return a.second > b.second || a.second == b.second && a.first < b.first;
}
vector<pair<string, int> > a, b, c;
multiset<int> m, mm;
string s;
int k, n, w;
int main() {
  cin >> n;
  for (int i = int(0); i < int(n); ++i) {
    cin >> s >> k;
    a.push_back(make_pair(s, k));
  }
  cin >> k;
  for (int i = int(0); i < int(k); ++i) {
    cin >> w;
    m.insert(w);
  }
  for (int i = int(k); i < int(n); ++i) m.insert(0);
  cin >> s;
  sort(a.begin(), a.end(), cmp);
  b = a;
  for (int i = int(0); i < int(n); ++i)
    if (a[i].first == s) w = i;
  b[w].second += *(m.rbegin());
  sort(b.begin(), b.end(), cmp);
  for (int i = int(0); i < int(n); ++i)
    if (b[i].first == s) w = i;
  mm = m;
  m.erase(m.find(*m.rbegin()));
  for (int i = int(0); i < int(w); ++i) {
    m.erase(m.find(*m.rbegin()));
  }
  for (int i = int(w + 1); i < int(n); ++i) {
    b[i].second += *m.begin();
    m.erase(m.begin());
  }
  sort(b.begin(), b.end(), cmp);
  for (int i = int(0); i < int(n); ++i)
    if (b[i].first == s) w = i;
  cout << w + 1;
  cout << ' ';
  m = mm;
  b = a;
  for (int i = int(0); i < int(n); ++i)
    if (a[i].first == s) w = i;
  b[w].second += *(m.begin());
  sort(b.begin(), b.end(), cmp);
  for (int i = int(0); i < int(n); ++i)
    if (b[i].first == s) w = i;
  m.erase(m.begin());
  for (int i = int(w + 1); i < int(n); ++i) {
    int need = b[w].second - b[i].second;
    if (b[w].first < b[i].first) ++need;
    multiset<int>::iterator q = m.lower_bound(need);
    if (q != m.end()) {
      b[i].second += *q;
      m.erase(q);
    }
  }
  sort(b.begin(), b.end(), cmp);
  for (int i = int(0); i < int(n); ++i)
    if (b[i].first == s) w = i;
  cout << w + 1;
  return 0;
}
