#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100005, MaxL = 24, MaxC = 0x3F3F3F3F, NA = -1;
char s[MaxN][MaxL];
int a[MaxN];
int b[MaxN];
char buf[MaxL];
int k, m, n;
inline bool cless(pair<int, string> a, pair<int, string> b) {
  return a.first > b.first || (a.first == b.first && a.second < b.second);
}
int main(void) {
  int i, j, v, w;
  while (scanf(" %d", &n) != EOF) {
    for (i = 0; i < n; i++) scanf(" %s %d", s[i], &a[i]);
    memset(b, 0, sizeof(b));
    scanf(" %d", &m);
    for (i = 0; i < m; i++) scanf(" %d", &b[i]);
    scanf(" %s", buf);
    sort(b, b + n);
    reverse(b, b + n);
    vector<pair<int, string> > x, x0;
    for (i = 0; i < n; i++) x.push_back(make_pair(a[i], s[i]));
    sort(x.begin(), x.end(), cless);
    for (k = 0; k < n; k++)
      if (x[k].second == buf) break;
    assert(k < n);
    x0 = x;
    j = 0;
    x[k].first += b[j++];
    for (i = n - 1; i >= 0; i--)
      if (i != k) x[i].first += b[j++];
    assert(j == n);
    sort(x.begin(), x.end(), cless);
    for (j = 0; j < n; j++)
      if (x[j].second == buf) break;
    assert(j < n);
    printf("%d ", j + 1);
    x = x0;
    x[k].first += b[n - 1];
    v = x[k].first;
    multiset<int> t;
    for (i = 0; i < n - 1; i++) t.insert(b[i]);
    sort(x.begin(), x.end(), cless);
    for (k = 0; k < n; k++)
      if (x[k].second == buf) break;
    assert(k < n);
    j = k;
    for (i = n - 1; i > k; i--) {
      w = v - x[i].first + !(x[i].second < buf);
      multiset<int>::iterator it = t.lower_bound(w);
      if (it != t.end()) {
        j++;
        t.erase(it);
      }
    }
    printf("%d\n", j + 1);
  }
  return 0;
}
