#include <bits/stdc++.h>
using namespace std;
struct node {
  string name;
  int score, index;
};
node a[100001];
int b[100001];
int cmp(const void *a, const void *b) {
  struct node *aa = (node *)a;
  struct node *bb = (node *)b;
  if (aa->score != bb->score)
    return aa->score - bb->score;
  else {
    if (aa->name > bb->name) return -1;
    if (aa->name < bb->name) return 1;
    return 0;
  }
}
int cmpfan(const void *a, const void *b) {
  struct node *aa = (node *)a;
  struct node *bb = (node *)b;
  if (aa->score != bb->score)
    return bb->score - aa->score;
  else {
    if (aa->name > bb->name) return 1;
    if (aa->name < bb->name) return -1;
    return 0;
  }
}
int cmpint(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int main() {
  string s;
  int m, n, i, low, high;
  while (cin >> m) {
    for (i = 1; i <= m; i++) {
      cin >> a[i].name;
      cin >> a[i].score;
      a[i].index = i;
    }
    memset(b, 0, sizeof(b));
    cin >> n;
    for (i = 1; i <= n; i++) cin >> b[i];
    qsort(b + 1, n, sizeof(b[1]), cmpint);
    cin >> s;
    node ss;
    for (i = 1; i <= m; i++)
      if (a[i].name == s) ss = a[i];
    qsort(a + 1, m, sizeof(a[0]), cmp);
    int y = 2;
    int rank = 1;
    for (i = 1; i <= m; i++) {
      if (a[i].index == ss.index) continue;
      if (a[i].score + b[y] > ss.score + b[1])
        rank++;
      else if (a[i].score + b[y] == ss.score + b[1] && a[i].name < ss.name)
        rank++;
      y++;
    }
    high = rank;
    y = m - 1;
    qsort(a + 1, m, sizeof(a[0]), cmpfan);
    rank = 1;
    for (i = 1; i <= m; i++) {
      if (a[i].index == ss.index) continue;
      if (y == 0) break;
      while (y) {
        if (a[i].score + b[y] > ss.score + b[m]) {
          rank++;
          y--;
          break;
        } else if (a[i].score + b[y] == ss.score + b[m] &&
                   a[i].name < ss.name) {
          rank++;
          y--;
          break;
        }
        y--;
      }
    }
    low = rank;
    cout << high << " " << low << endl;
  }
}
