#include <bits/stdc++.h>
using namespace std;
vector<pair<int, string> > v;
int get(vector<int> &a, vector<int> &b) {
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int j = 0;
  int res = 0;
  for (int i = 0; i < (int)b.size() && j < (int)a.size(); i++) {
    while (j < (int)a.size() && a[j] < b[i]) {
      j++;
    }
    res += j < (int)a.size();
    j++;
  }
  return res;
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char s[40];
    int first;
    scanf("%s%d", s, &first);
    v.push_back(make_pair(first, string(s)));
  }
  vector<int> a(n, 0);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  string name;
  cin >> name;
  vector<int> sa, va, sb, vb;
  sa = a;
  sa.erase(sa.begin(), sa.begin() + 1);
  sb = a;
  sb.erase(sb.end() - 1, sb.end());
  for (int i = 0; i < (int)sb.size(); i++) {
    sb[i] = -sb[i];
  }
  int pa = a[0], pb = a.back();
  int val = -1;
  for (int i = 0; i < n; i++) {
    if (v[i].second == name) {
      val = v[i].first;
    }
  }
  for (int i = 0; i < n; i++) {
    if (v[i].second != name) {
      va.push_back(val + pa - v[i].first + (v[i].second > name));
      vb.push_back(-(val + pb - v[i].first - (v[i].second < name)));
    }
  }
  printf("%d %d\n", n - get(sb, vb), 1 + get(sa, va));
  return 0;
}
