#include <bits/stdc++.h>
using namespace std;
struct Team {
  string name;
  int a;
};
char s[1000];
int b[100000];
bool sortByScrore(const Team& a, const Team& b) {
  if (a.a != b.a) return a.a < b.a;
  return a.name > b.name;
}
bool win(Team a, Team b) {
  if (a.a > b.a) return true;
  if (a.a == b.a && a.name < b.name) return true;
  return false;
}
int main(int argc, char* argv[]) {
  int N;
  scanf("%d", &N);
  vector<Team> teams(N);
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    scanf("%d", &teams[i].a);
    teams[i].name = s;
  }
  int M;
  scanf("%d", &M);
  for (int i = 0; i < M; i++) {
    scanf("%d", b + i);
  }
  scanf("%s", s);
  int v = -1;
  for (int i = 0; i < N; i++) {
    if (teams[i].name == s) {
      v = i;
      break;
    }
  }
  swap(teams[0], teams[v]);
  M = N;
  sort(b, b + M);
  int bestPlace = 1;
  sort(teams.begin() + 1, teams.end(), sortByScrore);
  {
    teams[0].a += M ? b[M - 1] : 0;
    int canUseFrom = 0;
    int canUseTo = M - 2;
    for (int i = N - 1; i >= 1; i--) {
      if (canUseFrom <= canUseTo) {
        int ta = teams[i].a;
        teams[i].a += b[canUseFrom];
        if (win(teams[0], teams[i])) {
          canUseFrom++;
        } else {
          canUseTo--;
          bestPlace++;
        }
        teams[i].a = ta;
      }
    }
    teams[0].a -= M ? b[M - 1] : 0;
  }
  int worsPlace = 1;
  {
    teams[0].a += M ? b[0] : 0;
    int canUseFrom = 1;
    int canUseTo = M - 1;
    for (int i = 1; i < N; i++) {
      if (canUseFrom <= canUseTo) {
        int ta = teams[i].a;
        teams[i].a += b[canUseTo];
        if (win(teams[0], teams[i])) {
          canUseFrom++;
        } else {
          canUseTo--;
          worsPlace++;
        }
        teams[i].a = ta;
      }
    }
    teams[0].a -= M ? b[0] : 0;
  }
  printf("%d %d\n", bestPlace, worsPlace);
  return 0;
}
