#include <bits/stdc++.h>
using namespace std;
struct data {
  string name;
  int score;
  data() {}
  data(string name, int score) : name(name), score(score) {}
  const bool operator<(const data& other) const {
    if (score != other.score) return score > other.score;
    return name < other.name;
  }
  const bool operator==(const data& other) const { return name == other.name; }
};
data vasya;
int n, m, b[100005];
int best(vector<data> v) {
  sort(b, b + m);
  reverse(b, b + m);
  v.erase(find(v.begin(), v.end(), vasya));
  sort(v.rbegin(), v.rend());
  v.insert(v.begin(), vasya);
  for (int i = 0; i < m; i++) v[i].score += b[i];
  sort(v.begin(), v.end());
  return find(v.begin(), v.end(), vasya) - v.begin() + 1;
}
int worst(vector<data> v) {
  multiset<int> S;
  multiset<int>::iterator it;
  int idx;
  for (int i = 0; i < m; i++) S.insert(b[i]);
  idx = find(v.begin(), v.end(), vasya) - v.begin();
  if (m == n) v[idx].score += *S.begin(), S.erase(S.begin());
  sort(v.begin(), v.end());
  idx = find(v.begin(), v.end(), vasya) - v.begin();
  for (int i = idx + 1; i < (int)v.size() && S.size(); i++) {
    int add;
    if (v[i].name < vasya.name)
      add = v[idx].score - v[i].score;
    else
      add = v[idx].score - v[i].score + 1;
    it = S.lower_bound(add);
    if (it == S.end()) continue;
    v[i].score += *it;
    S.erase(it);
  }
  sort(v.begin(), v.end());
  return find(v.begin(), v.end(), vasya) - v.begin() + 1;
}
int main() {
  cin >> n;
  vector<data> v(n);
  for (int i = 0; i < n; i++) cin >> v[i].name >> v[i].score;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> b[i];
  cin >> vasya.name;
  vasya.score = v[find(v.begin(), v.end(), vasya) - v.begin()].score;
  int place1 = best(v);
  int place2 = worst(v);
  cout << place1 << " " << place2 << endl;
}
