#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> mapa;
vector<int> pos;
int n, m, mid;
double val;
vector<double> v;
int solve1() {
  int j = 0, r = mid + 1;
  double auxval = val;
  if (m == n) val += double(pos[j++]);
  for (int i = mid + 1; i < n; i++) {
    while (j < m) {
      if (v[i] + double(pos[j]) > val) {
        r++;
        j++;
        break;
      }
      j++;
    }
  }
  val = auxval;
  return r;
}
int solve2() {
  val += double(pos[m - 1]);
  int aux = m - (n - mid) - 1, j = 0, r = mid + 1;
  for (int i = mid - 1; i >= 0; i--) {
    while (aux >= 0) {
      if (v[i] + double(pos[aux]) < val) {
        r--;
        aux--;
        goto oki;
      }
      v[j] += double(pos[aux]);
      aux--;
      j++;
    }
    if (aux < 0) {
      if (v[i] < val) r--;
    }
  oki:;
  }
  return r;
}
int main() {
  int aux;
  scanf("%d", &n);
  for (int i = (0), _i = (n); i < _i; ++i) {
    cin >> s >> aux;
    mapa[s] = aux;
  }
  scanf("%d", &m);
  if (m) {
    pos.resize(m);
    for (int i = (0), _i = (m); i < _i; ++i) scanf("%d", &pos[i]);
  }
  cin >> s;
  double dd = 1.0;
  for (map<string, int>::iterator it = mapa.begin(); it != mapa.end(); it++) {
    dd -= 1e-6;
    v.push_back(double(it->second) + dd);
    if (it->first == s) val = double(it->second) + dd;
  }
  mapa.clear();
  sort(v.rbegin(), v.rend());
  if (m) sort(pos.begin(), pos.end());
  mid = 0;
  for (int i = (0), _i = (n); i < _i; ++i) {
    if (v[i] == val) break;
    mid++;
  }
  if (m) {
    aux = solve1();
    printf("%d %d\n", solve2(), aux);
  } else {
    printf("%d %d\n", mid + 1, mid + 1);
  }
}
