#include <bits/stdc++.h>
struct dat {
  char n[30];
  int p;
};
bool operator<(dat a, dat b) {
  if (a.p == b.p) return (strcmp(a.n, b.n) == 1) ? 1 : 0;
  return a.p < b.p;
}
int n, m;
dat rac[2][100010];
int poi[100010];
char tar[30];
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", rac[0][i].n);
    scanf("%d", &rac[0][i].p);
    strcpy(rac[1][i].n, rac[0][i].n);
    rac[1][i].p = rac[0][i].p;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) scanf("%d", &poi[i]);
  scanf("%s", tar);
  std::sort(rac[0], rac[0] + n);
  std::sort(rac[1], rac[1] + n);
  std::sort(poi, poi + m);
  int no_p;
  for (int i = 0; i < n; ++i)
    if (strcmp(rac[0][i].n, tar) == 0) {
      no_p = i;
      break;
    }
  if (m != 0) rac[0][no_p].p += poi[m - 1];
  for (int i = 0, j = m - 2; i < n && j >= 0; ++i) {
    if (i == no_p) continue;
    rac[0][i].p += poi[j--];
  }
  if (n - 1 < m) rac[1][no_p].p += poi[0];
  std::sort(rac[1], rac[1] + n);
  for (int i = 0; i < n; ++i)
    if (strcmp(rac[1][i].n, tar) == 0) {
      no_p = i;
      break;
    }
  for (int i = no_p - 1, j = (m == n) ? 1 : 0; i >= 0 && j < m; --i) {
    while (j < m && (rac[1][i].p + poi[j] < rac[1][no_p].p ||
                     (rac[1][i].p + poi[j] == rac[1][no_p].p &&
                      strcmp(rac[1][i].n, rac[1][no_p].n) == 1)))
      ++j;
    if (j < m) rac[1][i].p += poi[j++];
  }
  std::sort(rac[0], rac[0] + n);
  std::sort(rac[1], rac[1] + n);
  for (int i = 0; i < n; ++i)
    if (strcmp(rac[0][i].n, tar) == 0) printf("%d ", n - i);
  for (int i = 0; i < n; ++i)
    if (strcmp(rac[1][i].n, tar) == 0) printf("%d\n", n - i);
  return 0;
}
