#include <bits/stdc++.h>
using namespace std;
struct node {
  string s;
  int c;
  node() {}
  node(string q, int w) {
    s = q;
    c = w;
  }
  bool operator<(const node gg) const {
    if (c == gg.c) return s < gg.s;
    return c > gg.c;
  }
};
node a[120000];
node b[120000];
int n, m;
int gt[120000];
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    char ss[30];
    int q;
    scanf("%s%d", ss, &q);
    a[i] = node((string)ss, q);
    b[i] = a[i];
  }
  int u, d;
  sort(a, a + n);
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d", gt + i);
  }
  for (i = m; i < n; i++) gt[i] = 0;
  m = n;
  sort(gt, gt + m, greater<int>());
  char s[30];
  scanf("%s", s);
  int pos;
  for (i = 0; i < n; i++) {
    if (a[i].s == (string)s) {
      pos = i;
      break;
    }
  }
  a[pos].c += gt[0];
  if (n - pos >= m) {
    sort(a, a + n);
    for (i = 0; i < n; i++) {
      if (a[i].s == (string)s) {
        u = i + 1;
        break;
      }
    }
  } else {
    int rem = m - (n - pos);
    int jp = n - pos;
    for (i = pos - 1; i >= 0; i--) {
      for (j = jp; j < m; j++) {
        node tmp = a[i];
        a[i].c += gt[j];
        if ((a[i] < a[pos]) == false) {
          break;
        }
        a[i] = tmp;
      }
      if (j == m) {
        for (k = i; k >= max(0, i - rem); k--) {
          a[k].c = 10000000;
        }
        break;
      }
      rem--;
      jp = j + 1;
    }
    sort(a, a + n);
    for (i = 0; i < n; i++) {
      if (a[i].s == (string)s) {
        u = i + 1;
        break;
      }
    }
  }
  for (i = m; i < n; i++) gt[i] = 0;
  m = n;
  sort(gt, gt + n);
  for (i = 0; i < n; i++) a[i] = b[i];
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    if (a[i].s == (string)s) {
      pos = i;
      break;
    }
  }
  a[pos].c += gt[0];
  int jp = 1;
  int qian = pos, hou = n - pos - 1;
  for (i = 0; i < pos; i++) {
    a[i].c += gt[jp++];
  }
  for (i = pos + 1; i < n; i++) {
    for (j = jp; j < n; j++) {
      node tmp = a[i];
      a[i].c += gt[j];
      if ((a[i] < a[pos]) == true) {
        break;
      }
      a[i] = tmp;
    }
    if (j == n) {
      for (k = i; k < n; k++) {
        a[k].c = -10000;
      }
      break;
    }
    jp = j + 1;
  }
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    if (a[i].s == (string)s) {
      d = i + 1;
      break;
    }
  }
  printf("%d %d\n", u, d);
  return 0;
}
