#include <bits/stdc++.h>
using namespace std;
struct Player {
  int score;
  string name;
};
int N, M, scores[100002];
bool cmp(const Player &a, const Player &b) {
  if (a.score != b.score) return a.score > b.score;
  return a.name < b.name;
}
vector<Player> s, os;
int main() {
  string vasya;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    char c[55];
    int n;
    scanf("%s %d", c, &n);
    s.push_back(Player{n, string(c)});
  }
  scanf("%d", &M);
  for (int i = 0; i < M; i++) scanf("%d", &scores[i]);
  M = N;
  cin >> vasya;
  sort(scores, scores + M);
  os = s;
  sort(s.begin(), s.end(), cmp);
  int maxScore = scores[M - 1];
  int vasyaScore, vasyaInd;
  for (int i = 0; i < N; i++)
    if (s[i].name == vasya) vasyaScore = s[i].score, vasyaInd = i;
  int noway = 0;
  for (int i = 0; i < N; i++) {
    if (s[i].score < vasyaScore + maxScore ||
        (s[i].score == vasyaScore + maxScore && s[i].name >= vasya))
      break;
    noway++;
  }
  int j = M - 2;
  s[vasyaInd].score += maxScore;
  for (int i = 0; i < noway; i++) {
    s[i].score += scores[j];
    j--;
  }
  j = 0;
  for (int i = noway; i < N; i++) {
    if (s[i].name == vasya) continue;
    s[i].score += scores[j];
    j++;
  }
  sort(s.begin(), s.end(), cmp);
  for (int i = 0; i < N; i++)
    if (s[i].name == vasya) vasyaInd = i + 1;
  printf("%d ", vasyaInd);
  s = os;
  sort(s.begin(), s.end(), cmp);
  for (int i = 0; i < N; i++)
    if (s[i].name == vasya) vasyaInd = i;
  s[vasyaInd].score += scores[0];
  vasyaScore = s[vasyaInd].score;
  sort(s.begin(), s.end(), cmp);
  for (int i = 0; i < N; i++)
    if (s[i].name == vasya) vasyaInd = i;
  j = M - 1;
  for (int i = N - 1; i > vasyaInd; i--) {
    if (s[i].score + scores[j] > vasyaScore ||
        (s[i].score + scores[j] == vasyaScore && s[i].name < vasya)) {
      s[i].score += scores[j];
      j--;
    }
  }
  sort(s.begin(), s.end(), cmp);
  for (int i = 0; i < N; i++)
    if (s[i].name == vasya) vasyaInd = i + 1;
  printf("%d\n", vasyaInd);
}
