#include <bits/stdc++.h>
using namespace std;
struct node {
  char name[21];
  int score;
  bool operator<(const node &a) const {
    if (score != a.score) return score > a.score;
    return strcmp(name, a.name) < 0;
  }
} stu[100005], tmp[100005];
int b[100005];
bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  int n, m, i, j, j1, k, high, low, t;
  char str[30];
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; i++) scanf("%s%d", stu[i].name, &stu[i].score);
    scanf("%d", &m);
    for (i = 0; i < m; i++) scanf("%d", &b[i]);
    sort(b, b + n, cmp);
    sort(stu, stu + n);
    for (i = 0; i < n; i++) tmp[i] = stu[i];
    scanf("%s", str);
    for (k = 0;; k++)
      if (strcmp(str, stu[k].name) == 0) break;
    t = stu[k].score;
    if (m) t += b[0];
    i = n - k;
    j = k - 1;
    high = k + 1;
    j1 = 0;
    while (i < m) {
      if (b[i] + stu[j].score < t ||
          (b[i] + stu[j].score == t && strcmp(stu[j].name, str) > 0)) {
        j--;
        high--;
      } else
        stu[j1++].score += b[i];
      i++;
    }
    while (j >= 0 && (t > stu[j].score) ||
           (t == stu[j].score && strcmp(str, stu[j].name) < 0)) {
      j--;
      high--;
    }
    for (i = 0; i < n; i++) stu[i] = tmp[i];
    low = k + 1;
    t = stu[k].score;
    if (m == n) {
      t += b[n - 1];
      m--;
    }
    i = m - 1;
    j = k + 1;
    while (i >= 0 && j < n) {
      if (b[i] + stu[j].score > t ||
          (b[i] + stu[j].score == t && strcmp(stu[j].name, str) < 0)) {
        low++;
        j++;
      }
      i--;
    }
    printf("%d %d\n", high, low);
  }
  return 0;
}
