#include <bits/stdc++.h>
using namespace std;
int N, M, b[100007];
pair<int, string> A[100007], B[100007];
char st[1111];
string Name;
inline int Calc1() {
  int p = 0;
  for (int i = 0; i < N; i++)
    if (A[i].second == Name) p = i;
  A[p].first -= b[0];
  for (int i = 0, j = N - 1; i < N; i++)
    if (p != i) A[i].first -= b[j--];
  sort(A, A + N);
  for (int i = 0; i < N; i++)
    if (A[i].second == Name) return i + 1;
}
inline int Calc2() {
  int p = 0;
  for (int i = 0; i < N; i++)
    if (B[i].second == Name) p = i;
  B[p].first -= b[N - 1];
  for (int i = 0, j = N - 2; i < N; i++)
    if (p != i) {
      if (B[i].second < Name) {
        for (; j >= 0 && B[i].first - b[j] > B[p].first; j--)
          ;
        if (j >= 0) B[i].first -= b[j--];
      } else {
        for (; j >= 0 && B[i].first - b[j] >= B[p].first; j--)
          ;
        if (j >= 0) B[i].first -= b[j--];
      }
    }
  sort(B, B + N);
  for (int i = 0; i < N; i++)
    if (B[i].second == Name) return i + 1;
}
int main() {
  scanf("%d", &N);
  for (int i = 0, k; i < N; i++) {
    scanf("%s%d", st, &k);
    A[i].first = -k;
    A[i].second = st;
  }
  scanf("%d", &M);
  for (int i = 0; i < M; i++) scanf("%d", &b[i]);
  sort(b, b + N);
  reverse(b, b + N);
  scanf("%s", st);
  Name = st;
  sort(A, A + N);
  for (int i = 0; i < N; i++) B[i] = A[i];
  int L = Calc1();
  int R = Calc2();
  printf("%d %d\n", L, R);
  return 0;
}
