#include <bits/stdc++.h>
using namespace std;
int n, m;
bool d[100005];
string name;
bool comp(pair<string, int> p, pair<string, int> p2) {
  if (p.second > p2.second) return true;
  if (p.second == p2.second && p.first < p2.first)
    return true;
  else
    return false;
}
int ff(pair<string, int> p[]) {
  for (int i = 0; i < n; i++)
    if (name == p[i].first) return i;
}
int fmax(pair<string, int> q[], int a[], int idx) {
  int i, k;
  q[idx].second += a[m - 1];
  for (i = n - 1, k = m - 2; i >= 0 && k >= 0; i--, k--) {
    if (a[k] == -1)
      i++;
    else if (i == idx)
      k++;
    else {
      if (q[i].second + a[k] > q[idx].second)
        i++;
      else if (q[i].second + a[k] == q[idx].second && q[idx].first > q[i].first)
        i++;
      else {
        q[i].second += a[k];
        a[k] = -1;
      }
    }
  }
  for (i = 0, k = m - 2; i < n && k >= 0; i++, k--) {
    if (a[k] == -1)
      i--;
    else if (i == idx)
      k++;
    else {
      q[i].second += a[k];
      a[k] = -1;
    }
  }
  sort(q, q + n, comp);
  return ff(q);
}
int fmin(pair<string, int> q[], int a[], int idx) {
  int i, k;
  d[idx] = false;
  if (m == n) {
    q[idx].second += a[0];
    a[0] = -1;
  }
  for (i = idx + 1, k = 0; i < n && k < m; i++, k++) {
    if (a[k] == -1)
      i--;
    else {
      if (q[i].second + a[k] < q[idx].second)
        i--;
      else if (q[i].second + a[k] == q[idx].second && q[idx].first < q[i].first)
        i--;
      else {
        q[i].second += a[k];
        a[k] = -1;
        d[i] = false;
      }
    }
  }
  for (i = idx - 1, k = m - 1; i >= 0 && k >= 0; i--, k--) {
    if (a[k] == -1)
      i++;
    else {
      if (q[i].second + a[k] < q[idx].second)
        i++;
      else if (q[i].second + a[k] == q[idx].second && q[idx].first < q[i].first)
        i++;
      else {
        q[i].second += a[k];
        a[k] = -1;
        d[i] = false;
      }
    }
  }
  for (i = 0, k = m - 1; k >= 0 && i < n; i++, k--) {
    if (a[k] == -1)
      i--;
    else if (d[i] == false)
      k++;
    else {
      q[i].second += a[k];
      a[k] = -1;
      d[i] = false;
    }
  }
  sort(q, q + n, comp);
  return ff(q);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  pair<string, int> p[100005], q[100005];
  int i, t, idx, mn, mx, a[100005], b[100005];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> name >> t;
    p[i] = make_pair(name, t);
    q[i] = p[i];
    d[i] = true;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  cin >> name;
  sort(p, p + n, comp);
  sort(q, q + n, comp);
  sort(a, a + m);
  sort(b, b + m);
  idx = ff(p);
  if (m <= 0)
    cout << 1 + idx << " " << 1 + idx;
  else
    cout << 1 + fmax(p, a, idx) << " " << 1 + fmin(q, b, idx);
  return 0;
}
