#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int sum, suf, pre, max;
} Node;
int toint(const string& s) {
  stringstream ss;
  ss << s;
  int x;
  ss >> x;
  return x;
}
const int MAXN = 2e5 + 100;
const int UP = 31;
const long long int highest = 1e18;
const double Phi = 1.618033988749894;
const int logn = 20;
const double root5 = 2.236067977;
const int mod = 1e9 + 7;
const int ini = -1e9;
const int N = 1e5 + 10;
struct player {
  string name;
  int a;
};
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 n, m;
player p[N];
int b[N];
player vasya;
int solve1() {
  int score = 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] > score ||
                        (p[i].a + b[cur] == score && p[i].name < vasya.name)))
      cur--;
    if (cur < 0) break;
    cur--;
    bad++;
  }
  return (n - bad);
}
int solve2() {
  int score = vasya.a + b[0];
  int cur = 1;
  int good = 0;
  for (int i = 0; i < n; ++i) {
    while (cur < n && (p[i].a + b[cur] < score ||
                       (p[i].a + b[cur] == score && p[i].name > vasya.name)))
      cur++;
    if (cur == n) break;
    cur++;
    good++;
  }
  return (good + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    char tmp[50];
    scanf("%s%d", &tmp, &p[i].a);
    p[i].name = tmp;
  }
  scanf("%d", &m);
  for (int i = 0; i < 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 < 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() << "\n";
  return 0;
}
