#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int INF = (int)1E9 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
struct play {
  string name;
  int point;
  play() {}
  bool operator<(const play& a) const {
    if (point != a.point) return point > a.point;
    return name < a.name;
  }
};
const int NMAX = 200 * 1000;
int n, b[NMAX], m;
play a[NMAX], tmp[NMAX];
char buf[100];
int findName(string s) {
  int pos = -1;
  for (int i = 0; i < int(n); ++i)
    if (a[i].name == s) pos = i;
  return pos;
}
int main() {
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    int ps;
    scanf(" %s %d ", buf, &ps);
    a[i].name = buf;
    a[i].point = ps;
  }
  sort(a, a + n);
  cin >> m;
  for (int i = 0; i < int(m); ++i) scanf("%d", &b[i]);
  string vas;
  cin >> vas;
  m = -1;
  int maxPlace = -1;
  {
    multiset<int> ps(b, b + n);
    for (int i = 0; i < int(n); ++i) tmp[i] = a[i];
    a[findName(vas)].point += *ps.rbegin();
    ps.erase(--ps.end());
    sort(a, a + n);
    int cpos = findName(vas), maxV = true;
    for (int i = 0; i < int(n); ++i) {
      if (i == cpos) {
        maxV ^= 1;
      } else {
        if (!maxV) {
          a[i].point += *ps.begin();
          if (a[i] < a[cpos]) {
            a[i].point -= *ps.begin();
            a[i].point += *ps.rbegin();
            ps.erase(--ps.end());
          } else {
            ps.erase(ps.begin());
          }
        } else {
          a[i].point += *ps.rbegin();
          ps.erase(--ps.end());
        }
      }
    }
    sort(a, a + n);
    maxPlace = findName(vas);
    for (int i = 0; i < int(n); ++i) a[i] = tmp[i];
  }
  int minPlace = -1;
  {
    multiset<int> ps(b, b + n);
    for (int i = 0; i < int(n); ++i) tmp[i] = a[i];
    a[findName(vas)].point += *ps.begin();
    ps.erase(ps.begin());
    sort(a, a + n);
    int cpos = findName(vas), maxV = false;
    for (int i = 0; i < int(n); ++i) {
      if (i == cpos) {
        maxV ^= 1;
      } else {
        if (maxV) {
          int needPoint = -1;
          if (a[i].name < vas) {
            needPoint = a[cpos].point - a[i].point;
          } else
            needPoint = a[cpos].point - a[i].point + 1;
          multiset<int>::iterator it = ps.lower_bound(needPoint);
          if (it == ps.end()) {
            a[i].point += *ps.begin();
            ps.erase(ps.begin());
          } else {
            a[i].point += *it;
            ps.erase(it);
          }
        } else {
          a[i].point += *ps.begin();
          ps.erase(ps.begin());
        }
      }
    }
    sort(a, a + n);
    minPlace = findName(vas);
    for (int i = 0; i < int(n); ++i) a[i] = tmp[i];
  }
  cout << maxPlace + 1 << " " << minPlace + 1 << endl;
  return 0;
}
