#include <bits/stdc++.h>
using namespace std;
string s[100000];
int n, m, a[100000], b[100000];
int main() {
  char str[1000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%d", str, a + i);
    s[i] = str;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  sort(b, b + n);
  scanf("%s", str);
  multiset<int> ls, hs;
  vector<pair<int, string>> lo, hi;
  for (int i = 0; i < n; i++)
    if (s[i] == str) {
      lo.push_back({-a[i] - b[0], s[i]});
      hi.push_back({-a[i] - b[n - 1], s[i]});
    }
  for (int i = 1; i < n; i++) {
    ls.insert(b[i]);
    hs.insert(b[i - 1]);
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == str) continue;
    auto lp = ls.lower_bound(-lo[0].first - a[i] + (s[i] > str));
    if (lp == ls.end()) lp = ls.begin();
    lo.push_back({-a[i] - *lp, s[i]});
    ls.erase(lp);
    auto hp = hs.lower_bound(-hi[0].first - a[i] + (s[i] > str));
    if (hp != hs.end() && hp != hs.begin())
      --hp;
    else
      hp = hs.find(*hs.rbegin());
    hi.push_back({-a[i] - *hp, s[i]});
    hs.erase(hp);
  }
  sort(lo.begin(), lo.end());
  sort(hi.begin(), hi.end());
  int la = 0, ha = 0;
  for (int i = 0; i < n; i++) {
    if (lo[i].second == str) la = i + 1;
    if (hi[i].second == str) ha = i + 1;
  }
  printf("%d %d\n", ha, la);
}
