#include <bits/stdc++.h>
using namespace std;
struct node {
  string name;
  long long s;
} a[100005], aa[100005];
long long n, m, b[100005];
string me;
bool cmp(node x, node y) {
  if (x.s == y.s)
    return x.name < y.name;
  else
    return x.s > y.s;
}
bool cmp2(long long x, long long y) { return x > y; }
long long getmin() {
  long long pos, s;
  for (long long i = 1; i <= n; i++)
    if (aa[i].name == me) {
      pos = i, s = aa[i].s;
      break;
    }
  if (m == n) aa[pos].s += b[m];
  sort(aa + 1, aa + 1 + n, cmp);
  for (long long i = 1; i <= n; i++)
    if (aa[i].name == me) {
      pos = i, s = aa[i].s;
      break;
    }
  long long now = m;
  if (m == n) now--;
  long long ans = pos;
  for (long long i = pos + 1; i <= n; i++) {
    if (now == 0) break;
    node tmp;
    tmp.s = aa[i].s + b[now], tmp.name = aa[i].name;
    if (!cmp(tmp, aa[pos]))
      now--, i--;
    else
      now--, ans++;
  }
  return ans;
}
long long getmax() {
  long long pos, s;
  for (long long i = 1; i <= n; i++)
    if (a[i].name == me) {
      pos = i, s = a[i].s;
      break;
    }
  if (m) a[pos].s += b[1];
  sort(a + 1, a + 1 + n, cmp);
  for (long long i = 1; i <= n; i++)
    if (a[i].name == me) {
      pos = i, s = a[i].s;
      break;
    }
  long long now = 2;
  now += pos - 1;
  for (long long i = n; i > pos && now <= m; i--) {
    a[i].s += b[now];
    now++;
  }
  sort(a + 1, a + 1 + n, cmp);
  for (long long i = 1; i <= n; i++)
    if (a[i].name == me) {
      pos = i, s = a[i].s;
      break;
    }
  return pos;
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i].name >> a[i].s;
  cin >> m;
  for (long long i = 1; i <= m; i++) cin >> b[i];
  cin >> me;
  sort(a + 1, a + 1 + n, cmp);
  sort(b + 1, b + 1 + m, cmp2);
  for (long long i = 1; i <= n; i++) aa[i] = a[i];
  cout << getmax() << " " << getmin();
  return 0;
}
