#include <bits/stdc++.h>
using namespace std;
struct Msg {
  char name[23];
  int v;
} msg[110000];
int b[110000];
int cmp(const Msg &a, const Msg &b) { return a.v > b.v; }
int cmp2(const Msg &a, const Msg &b) { return a.v < b.v; }
int cmp3(const int &a, const int &b) { return a > b; }
int find(int v, int l, int r) {
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (b[mid] >= v)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return r;
}
int find2(int v, int l, int r) {
  int m = r;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (b[mid] < v)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return r;
}
bool check(char *a, char *b) { return strcmp(a, b) < 0; }
int main() {
  int n, m, sco;
  char the[23];
  while (scanf("%d", &n) == 1) {
    int i, j, l, r;
    for (i = 0; i < n; ++i) {
      scanf("%s%d", msg[i].name, &msg[i].v);
    }
    memset(b, 0, sizeof(b));
    scanf("%d", &m);
    for (i = 0; i < m; ++i) {
      scanf("%d", &b[i]);
    }
    scanf("%s", the);
    for (i = 0; i < n; ++i) {
      if (strcmp(the, msg[i].name) > 0) msg[i].v++;
    }
    sort(msg, msg + n, cmp);
    sort(b, b + n, cmp3);
    for (i = 0; i < n; ++i) {
      if (strcmp(msg[i].name, the) == 0) {
        sco = msg[i].v;
        break;
      }
    }
    int ans1 = 1, ans2 = 1;
    l = 1, r = n - 1;
    sco += b[0];
    for (i = 0; i < n; ++i) {
      if (strcmp(the, msg[i].name) == 0) continue;
      if (msg[i].v + b[r] > sco) {
        ++l;
        ans1++;
      } else if (msg[i].v + b[l] <= sco) {
        ++l;
        continue;
      } else {
        --r;
      }
    }
    sco -= b[0];
    sco += b[n - 1];
    l = 0, r = n - 2;
    for (i = 0; i <= n; ++i) {
      if (strcmp(the, msg[i].name) == 0) continue;
      if (msg[i].v + b[r] > sco) {
        --r;
        ans2++;
      } else if (msg[i].v + b[l] <= sco) {
        break;
      } else {
        if (l > r) break;
        r = find(sco - msg[i].v + 1, l, r) - 1;
        ans2++;
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
