#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
template <class T>
T sqr(T x) {
  return x * x;
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
struct Racer {
  char name[22];
  int score;
  bool operator<(const Racer& next) const {
    return score > next.score ||
           score == next.score && strcmp(name, next.name) < 0;
  }
};
int b[100005];
Racer r1[100005], r2[100005];
char vasname[25];
int main(int argc, char** argv) {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s%d", r1[i].name, &r1[i].score);
    r2[i] = r1[i];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i]);
  }
  sort(b, b + n);
  scanf("%s", vasname);
  for (int i = 0; i < n; ++i) {
    if (strcmp(r1[i].name, vasname) == 0) {
      r1[i].score += b[n - 1];
      r2[i].score += b[0];
    }
  }
  sort(r1, r1 + n);
  sort(r2, r2 + n);
  int hres = 0, lres = 0;
  int left = 0, right = n - 2, i = 0;
  for (i = 0; strcmp(r1[i].name, vasname); ++i, ++hres, --right)
    ;
  int vasscore = r1[i].score;
  ++i;
  for (; i < n; ++i) {
    if (r1[i].score + b[left] < vasscore ||
        r1[i].score + b[left] == vasscore && strcmp(r1[i].name, vasname) > 0)
      ++left;
    else {
      ++hres;
      --right;
    }
  }
  left = 1, right = n - 1, i = 0;
  for (i = 0; strcmp(r2[i].name, vasname); ++i, ++lres, ++left)
    ;
  vasscore = r2[i].score;
  ++i;
  for (; i < n; ++i) {
    for (; left <= right; ++left) {
      if (r2[i].score + b[left] > vasscore ||
          r2[i].score + b[left] == vasscore &&
              strcmp(r2[i].name, vasname) < 0) {
        ++left;
        ++lres;
        break;
      }
    }
  }
  printf("%d %d\n", hres + 1, lres + 1);
  return (EXIT_SUCCESS);
}
