#include <bits/stdc++.h>
using namespace std;
struct Data {
  int F;
  string S;
};
Data arr[100005], brr[100005];
bool compare(Data a, Data b) {
  if (a.F != b.F)
    return a.F < b.F;
  else
    return a.S > b.S;
}
vector<int> v;
int score[100005], n, m;
string nick;
int solvemx(int idx) {
  sort(score, score + m);
  if (m == n) arr[idx].F += score[0];
  int Score = arr[idx].F;
  sort(arr, arr + n, compare);
  for (int i = 0; i < n; i++) {
    if (arr[i].S == nick) idx = i;
  }
  int j = 0;
  if (m == n) j++;
  for (int i = idx - 1; i >= 0; i--) {
    int diff = Score - arr[i].F;
    while (diff >= score[j] && j < m) {
      if (diff == score[j] && arr[idx].S > arr[i].S) break;
      v.push_back(score[j]);
      j++;
    }
    if (j == m) break;
    arr[i].F += score[j];
    j++;
  }
  for (int i = j; i < m; i++) v.push_back(score[i]);
  j = n - 1;
  int i;
  sort(v.begin(), v.end(), greater<int>());
  for (i = 0; j > idx && i < v.size(); j--) {
    arr[j].F += v[i];
    i++;
  }
  j = 0;
  for (; j < idx && i < v.size(); j++) {
    arr[j].F += v[i];
    i++;
  }
  v.clear();
  int pos = n, P = 0;
  sort(arr, arr + n, compare);
  for (int i = 0; i < n; i++) {
    if (arr[i].S == nick) {
      P = pos;
    }
    pos--;
  }
  return P;
}
int solvemn(int idx) {
  sort(score, score + m, greater<int>());
  brr[idx].F += score[0];
  int Score = brr[idx].F;
  sort(brr, brr + n, compare);
  for (int i = 0; i < n; i++) {
    if (brr[i].S == nick) idx = i;
  }
  int j = 1;
  for (int i = n - 1; i > idx; i--) {
    j++;
  }
  for (int i = 0; i < idx && j < m; i++) {
    brr[i].F += score[j];
    j++;
  }
  int pos = n, P;
  sort(brr, brr + n, compare);
  for (int i = 0; i < n; i++) {
    if (brr[i].S == nick) {
      P = pos;
    }
    pos--;
  }
  return P;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].S >> arr[i].F;
    brr[i] = arr[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) cin >> score[i];
  cin >> nick;
  int idx;
  for (int i = 0; i < n; i++) {
    if (arr[i].S == nick) {
      idx = i;
    }
  }
  cout << solvemn(idx) << " " << solvemx(idx) << endl;
  return 0;
}
