#include <bits/stdc++.h>
using namespace std;
int n, m, ans, sc;
string s[100005], name;
vector<pair<int, string> > v, vv;
int a[100005], b[100005];
bool cmp(pair<int, string> a, pair<int, string> b) {
  if (a.first < b.first) return 1;
  if (a.first == b.first) return a.second > b.second;
  return 0;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i] >> a[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> b[i];
  for (int i = m; i < n; i++) b[i] = 0;
  sort(b, b + n);
  cin >> name;
  for (int i = 0; i < n; i++) {
    if (s[i] != name)
      v.push_back(make_pair(a[i], s[i]));
    else
      sc = a[i];
  }
  sort(v.begin(), v.end(), cmp);
  int k, cur, ans1, ans2;
  k = sc + b[n - 1];
  cur = 0;
  ans1 = 1;
  vv = v;
  for (int i = n - 2; i >= 0; i--) {
    vv[i].first += b[cur];
    if (cmp(vv[i], {k, name}))
      cur++;
    else
      ans1++;
  }
  cur = n - 1;
  ans2 = 1;
  vv = v;
  k = sc + b[0];
  for (int i = 0; i < n - 1; i++) {
    vv[i].first += b[cur];
    if (!cmp(vv[i], {k, name})) cur--, ans2++;
  }
  cout << ans1 << ' ' << ans2;
  return 0;
}
