#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000002;
const long long INFLL = 100000000000000000ll;
const long long MOD = 1000000007;
struct Racer {
  int score;
  string name;
  Racer(string n, int s) : name(n), score(s){};
  friend bool operator<(Racer r1, Racer r2) {
    if (r1.score != r2.score) return r1.score > r2.score;
    return r1.name < r2.name;
  }
};
int B[1000005], N, M;
vector<Racer> R, R2;
int main() {
  cin >> N;
  string vasya;
  for (int i = (1); i <= (N); i++) {
    int score;
    string name;
    cin >> name >> score;
    R.push_back(Racer(name, score));
  }
  cin >> M;
  for (int i = (1); i <= (M); i++) scanf("%d", &B[i]);
  cin >> vasya;
  sort(B + 1, B + M + 1, greater<int>());
  sort(R.begin(), R.end());
  R2 = R;
  int idx;
  for (int i = (0); i <= (N - 1); i++)
    if (R2[i].name == vasya) idx = i;
  R2[idx].score += B[1];
  int p = 2;
  for (int i = (N - 1); i >= (0); i--) {
    if (i == idx) continue;
    if (p > M) continue;
    R2[i].score += B[p++];
  }
  sort(R2.begin(), R2.end());
  int ans1;
  for (int i = (0); i <= (N - 1); i++)
    if (R2[i].name == vasya) ans1 = i + 1;
  R2 = R;
  for (int i = (0); i <= (N - 1); i++)
    if (R2[i].name == vasya) idx = i;
  if (N == M) {
    R2[idx].score += B[M];
    sort(R2.begin(), R2.end());
    for (int i = (0); i <= (N - 1); i++)
      if (R2[i].name == vasya) idx = i;
  }
  multiset<int> s;
  for (int i = (1); i <= (min(M, N - 1)); i++) s.insert(B[i]);
  for (int i = (idx + 1); i <= (N - 1); i++) {
    auto it = R2[i].name < R2[idx].name
                  ? s.lower_bound(R2[idx].score - R2[i].score)
                  : s.upper_bound(R2[idx].score - R2[i].score);
    if (it == s.end()) break;
    R2[i].score += *it;
    s.erase(it);
  }
  sort(R2.begin(), R2.end());
  int ans2;
  for (int i = (0); i <= (N - 1); i++)
    if (R2[i].name == vasya) ans2 = i + 1;
  cout << ans1 << " " << ans2;
}
