#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
struct node {
  int v;
  char s[25];
  bool operator<(const node& t) const {
    return v != t.v ? v > t.v : strcmp(s, t.s) < 0;
  }
};
node a[maxn];
int b[maxn];
int geth(int pos, int n) {
  int l = 1, r = pos, ans;
  node p = a[pos];
  p.v += b[n];
  while (l <= r) {
    int m = l + r >> 1;
    int ok = 1;
    for (int i = m, j = 1; i < pos; ++i, ++j) {
      node t = a[i];
      t.v += b[j];
      if (t < p) {
        ok = 0;
        break;
      }
    }
    if (ok)
      ans = m, r = m - 1;
    else
      l = m + 1;
  }
  return ans;
}
int getl(int pos, int n) {
  int l = pos, r = n, ans;
  node p = a[pos];
  p.v += b[1];
  while (l <= r) {
    int m = l + r >> 1;
    int ok = 1;
    for (int i = m, j = n; i > pos; --i, --j) {
      node t = a[i];
      t.v += b[j];
      if (p < t) {
        ok = 0;
        break;
      }
    }
    if (ok)
      ans = m, l = m + 1;
    else
      r = m - 1;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%s%d", a[i].s, &a[i].v);
  sort(a + 1, a + 1 + n);
  int m;
  cin >> m;
  for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
  sort(b + 1, b + 1 + n);
  char nam[25];
  scanf("%s", nam);
  int pos;
  for (int i = 1; i <= n; ++i)
    if (strcmp(a[i].s, nam) == 0) pos = i;
  cout << geth(pos, n) << " " << getl(pos, n);
  return 0;
}
