#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct comp {
  bool operator()(pair<int, string> p1, pair<int, string> p2) {
    return p1.first < p2.first ||
           (p1.first == p2.first && p1.second > p2.second);
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> ms;
  for (int i = 0; i < n; i++) {
    string s;
    int x;
    cin >> s >> x;
    ms[s] = x;
  }
  int m;
  cin >> m;
  vector<int> v(n);
  for (int i = 0; i < m; i++) cin >> v[i];
  sort(v.begin(), v.end(), greater<int>());
  string vas;
  cin >> vas;
  set<pair<int, string>, comp> oth;
  int gct = 0;
  pair<int, string> vasp = {ms[vas] + v[0], vas};
  for (auto p : ms) {
    if (p.first == vas) continue;
    pair<int, string> p2 = {p.second, p.first};
    if (comp()(vasp, p2))
      gct++;
    else
      oth.insert(p2);
  }
  for (int i = 1; i < n; i++) {
    if (i <= gct) continue;
    auto it = oth.lower_bound({vasp.first - v[i], vas});
    if (it == oth.begin()) {
      gct++;
      continue;
    }
    it--;
    oth.erase(it);
  }
  cout << 1 + gct << ' ';
  gct = 0;
  sort(v.begin(), v.end());
  vasp = {ms[vas] + v[0], vas};
  for (auto p : ms) {
    if (p.first == vas) continue;
    pair<int, string> p2 = {p.second, p.first};
    if (comp()(vasp, p2))
      gct++;
    else
      oth.insert(p2);
  }
  for (int i = 1; i < n; i++) {
    if (i <= gct) continue;
    auto it = oth.lower_bound({vasp.first - v[i], vas});
    if (it == oth.end()) {
      continue;
    }
    gct++;
    oth.erase(it);
  }
  cout << 1 + gct;
  return 0;
}
