#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, string> a, pair<int, string> b) {
  if (a.first == b.first)
    return a.second > b.second;
  else
    return a.first < b.first;
}
char buf[50];
int main() {
  int n;
  cin >> n;
  vector<pair<int, string> > v;
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%s%d", buf, &t);
    v.push_back(make_pair(t, buf));
  }
  int m;
  scanf("%d", &m);
  vector<int> b(m);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  string name;
  scanf("%s", buf);
  name = buf;
  sort((b).begin(), (b).end());
  vector<int> bt = b;
  vector<pair<int, string> > vt;
  int ans = 0;
  int pos;
  for (int i = 0; i < n; i++)
    if (v[i].second == name) pos = i;
  if (b.size() > 0) {
    v[pos].first += b[m - 1];
    b.pop_back();
  }
  sort((v).begin(), (v).end(), comp);
  vt = v;
  for (int i = 0; i < n; ++i)
    if (v[i].second == name) {
      pos = i;
      break;
    }
  ans += n - pos;
  int it = (int)b.size() - (n - pos);
  it = max(it, 0);
  for (int i = 0; i < pos; i++) {
    if (it >= 0 && it < b.size()) {
      v[i].first += b[it];
      it--;
    }
    if (comp(v[pos], v[i])) ans++;
  }
  cout << ans << " ";
  if (m == 0) {
    cout << ans << endl;
    return 0;
  }
  b = bt;
  v = vt;
  if (b.size() > 0) v[pos].first -= b[(int)b.size() - 1];
  if (m == n) {
    v[pos].first += b[0];
    reverse((b).begin(), (b).end());
    b.pop_back();
    reverse((b).begin(), (b).end());
  }
  sort((v).begin(), (v).end(), comp);
  for (int i = 0; i < n; i++)
    if (v[i].second == name) {
      pos = i;
      break;
    }
  if (pos == 0) {
    cout << n << endl;
    return 0;
  }
  int tmp = v[pos].first - v[pos - 1].first;
  if (v[pos].second < v[pos - 1].second) tmp++;
  it = -1;
  for (int i = 0; i < b.size(); i++) {
    if (b[i] >= tmp) {
      it = i;
      break;
    }
  }
  if (it == -1) {
    cout << n - pos << endl;
    return 0;
  }
  int down = 0;
  for (int i = pos - 1; i >= 0; i--) {
    while (it < b.size() &&
           !comp(v[pos], make_pair(v[i].first + b[it], v[i].second)))
      it++;
    if (it >= b.size()) break;
    v[i].first += b[it];
    if (comp(v[pos], v[i]))
      down++;
    else
      break;
    it++;
  }
  cout << n - pos + down << endl;
  return 0;
}
