#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int score[maxn];
int n, m, pos;
string team;
struct Node {
  string team;
  int score;
  bool operator<(const Node rhs) const {
    if (this->score != rhs.score)
      return this->score > rhs.score;
    else if (this->score == rhs.score)
      return this->team < rhs.team;
  }
  Node() {}
  Node(string _team, int _score) : team(_team), score(_score) {}
} a[maxn];
bool cmp(const Node &a, const Node &b) { return a < b; }
int searchTeam(string team) {
  for (int i = 1; i <= n; i++)
    if (team == a[i].team) return i;
}
int searchScore(const Node &t) {
  int l = 1, r = n, mid, ans = 0;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (a[mid] < t) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ans;
}
int best() {
  int num = searchScore(Node(team, a[pos].score + score[m]));
  int ret = num + 1;
  for (int i = n, j = m - 1 - num; i > num && j >= 1; i--, j--) {
    if (i == pos) i--;
    while (i > num && j >= 1 &&
           !cmp(Node(team, a[pos].score + score[m]),
                Node(a[i].team, a[i].score + score[j]))) {
      ret++;
      j--;
    }
  }
  return ret;
}
int worst() {
  int j = 1;
  if (n == m) {
    a[pos].score += score[1];
    j++;
  }
  int num = searchScore(a[pos]);
  int ret = num + 1;
  for (int i = num + 1; i <= n && j <= m; i++, j++) {
    if (i == pos) i++;
    while (
        i <= n && j <= m &&
        cmp(Node(team, a[pos].score), Node(a[i].team, a[i].score + score[j]))) {
      j++;
    }
    if (i <= n && j <= m) ret++;
  }
  if (n == m) a[pos].score -= score[1];
  return ret;
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i].team >> a[i].score;
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> score[i];
    cin >> team;
    sort(score + 1, score + m + 1);
    sort(a + 1, a + n + 1, cmp);
    pos = searchTeam(team);
    cout << best() << ' ' << worst() << endl;
  }
  return 0;
}
