#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
struct Player {
  string name;
  int a;
};
int n, m;
Player p[100005];
int b[100005];
Player vasya;
inline bool operator<(const Player& p1, const Player& p2) {
  if (p1.a != p2.a) return p1.a > p2.a;
  return p1.name < p2.name;
}
int solve1() {
  int V = vasya.a + b[n - 1];
  int cur = n - 2;
  int bad = 0;
  for (int i = n - 2; i >= 0; i--) {
    while (cur >= 0 && (p[i].a + b[cur] > V ||
                        (p[i].a + b[cur] == V && p[i].name < vasya.name)))
      cur--;
    if (cur < 0) break;
    cur--;
    bad++;
  }
  return n - bad;
}
int solve2() {
  int V = vasya.a + b[0];
  int cur = 1;
  int good = 0;
  for (int i = 0; i < int(n - 1); i++) {
    while (cur < n && (p[i].a + b[cur] < V ||
                       (p[i].a + b[cur] == V && p[i].name > vasya.name)))
      cur++;
    if (cur == n) break;
    cur++;
    good++;
  }
  return good + 1;
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < int(n); i++) {
    char tmp[50];
    scanf("%s %d\n", &tmp, &p[i].a);
    p[i].name = tmp;
  }
  scanf("%d", &m);
  for (int i = 0; i < int(m); i++) {
    scanf("%d", &b[i]);
  }
  for (int i = m; i < n; i++) b[i] = 0;
  sort(b, b + n);
  cin >> vasya.name;
  for (int i = 0; i < int(n); i++) {
    if (p[i].name == vasya.name) {
      vasya.a = p[i].a;
      for (int j = i + 1; j < n; j++) {
        p[j - 1] = p[j];
      }
      break;
    }
  }
  sort(p, p + n - 1);
  cout << solve1() << " " << solve2();
  return 0;
}
