#include <bits/stdc++.h>
using namespace std;
class racer {
 public:
  string name;
  int score;
  racer() {
    name = "";
    score = 0;
  }
  racer(string _name, int _score) {
    name = _name;
    score = _score;
  }
};
int position(racer a[], int size, string value) {
  for (int i = 0; i < size; i++)
    if (a[i].name == value) return i + 1;
  return -1;
}
void qs_ab(racer a[], int left, int right) {
  int i = left, j = right;
  string key = a[(left + right) / 2].name;
  do {
    while (a[i].name < key) i++;
    while (a[j].name > key) j--;
    if (i <= j) {
      swap(a[i], a[j]);
      i++;
      j--;
    }
  } while (i <= j);
  if (i < right) qs_ab(a, i, right);
  if (j > left) qs_ab(a, left, j);
}
void qs(racer a[], int left, int right) {
  int i = left, j = right, key = a[(left + right) / 2].score;
  do {
    while (a[i].score > key) i++;
    while (a[j].score < key) j--;
    if (i <= j) {
      swap(a[i], a[j]);
      i++;
      j--;
    }
  } while (i <= j);
  if (i < right) qs(a, i, right);
  if (j > left) qs(a, left, j);
}
void QuichSort(racer a[], int n) {
  qs(a, 0, n - 1);
  int right;
  for (int left = 0; left < n - 1; left = right + 1) {
    right = left;
    while (a[right + 1].score == a[right].score) right++;
    if (right > left) qs_ab(a, left, right);
  }
}
void qs(int a[], int left, int right) {
  int i = left, j = right, key = a[(left + right) / 2];
  do {
    while (a[i] > key) i++;
    while (a[j] < key) j--;
    if (i <= j) {
      swap(a[i], a[j]);
      i++;
      j--;
    }
  } while (i <= j);
  if (i < right) qs(a, i, right);
  if (j > left) qs(a, left, j);
}
void QuichSort(int a[], int n) { qs(a, 0, n - 1); }
int main() {
  int n = 0, m = 0;
  cin >> n;
  racer *a = new racer[n];
  for (int i = 0; i < n; i++) cin >> a[i].name >> a[i].score;
  cin >> m;
  int *b = new int[n];
  for (int i = 0; i < m; i++) cin >> b[i];
  for (int i = m; i < n; i++) b[i] = 0;
  string name;
  cin >> name;
  int min = 0, max = 0;
  racer *score = new racer[n];
  QuichSort(a, n);
  QuichSort(b, m);
  int Vasya = position(a, n, name) - 1;
  for (int i = 0; i < n; i++) score[i] = a[i];
  for (int i = n - 1; i > Vasya; i--) score[i].score += b[n - i];
  score[Vasya].score += b[0];
  for (int i = Vasya - 1; i >= 0; i--) score[i].score += b[n - i - 1];
  QuichSort(score, n);
  min = position(score, n, name);
  for (int i = 0; i < n; i++) score[i] = a[i];
  Vasya = position(score, n, name) - 1;
  score[Vasya].score += b[n - 1];
  int larg;
  if (m < n)
    larg = m - 1;
  else
    larg = n - 2;
  int largus = larg, vasyus = Vasya + 1;
  for (; larg >= 0 && vasyus < n; vasyus++) {
    while (score[vasyus].score + b[larg] <= score[Vasya].score)
      if (larg > 0)
        larg--;
      else {
        larg--;
        break;
      }
    if (larg >= 0) {
      score[vasyus].score += b[larg];
      larg--;
      largus = larg;
    }
  }
  for (larg = largus; larg >= 0 && vasyus < n; vasyus++) {
    while (score[vasyus].score + b[larg] < score[Vasya].score)
      if (larg > 0)
        larg--;
      else {
        larg--;
        break;
      }
    if (larg >= 0) {
      score[vasyus].score += b[larg];
      larg--;
      largus = larg;
    }
  }
  for (vasyus = Vasya - 1; largus >= 0 && vasyus >= 0; vasyus--, largus--) {
    score[vasyus].score += b[largus];
  }
  QuichSort(score, n);
  max = position(score, n, name);
  cout << min << " " << max;
  return 0;
}
