#include <bits/stdc++.h>
using namespace std;
bool desc_sort(const int& lhs, const int& rhs) { return lhs > rhs; }
bool desc_pii_sort(const pair<int, int>& lhs, const pair<int, int>& rhs) {
  return lhs > rhs;
}
bool second_sort(const pair<int, int>& lhs, const pair<int, int>& rhs) {
  pair<int, int> a, b;
  a.first = lhs.second;
  a.second = lhs.first;
  b.first = rhs.second;
  b.second = rhs.first;
  return a < b;
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> second) {
  os << "{ ";
  for (auto s : second) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
inline long long fast_expo(long long base, long long power,
                           long long modulo = 1e0) {
  base %= modulo;
  if (base < 0LL) base += modulo;
  long long x = base, cnt = power, ans = 1LL;
  while (cnt) {
    if (cnt & 1LL) ans = (ans * x) % modulo;
    x = (x * x) % modulo;
    cnt >>= 1LL;
  }
  return ans;
}
inline long long inv(long long base, long long modulo = 1e0) {
  return fast_expo(base, modulo - 2LL, modulo);
}
bool sort_by_known(const pair<int, string>& lhs, const pair<int, string>& rhs) {
  if (lhs.first == rhs.first)
    return lhs.second > rhs.second;
  else
    return lhs.first < rhs.first;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, string>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].second >> v[i].first;
  }
  int m;
  cin >> m;
  vector<int> b;
  for (int i = 0; i < m; i++) {
    int r;
    cin >> r;
    b.push_back(r);
  }
  while ((b).size() < n) {
    b.push_back(0);
  }
  sort((b).begin(), (b).end());
  string vas;
  cin >> vas;
  int p;
  for (int i = 0; i < n; i++) {
    if (v[i].second == vas) {
      p = v[i].first;
      v.erase(v.begin() + i);
    }
  }
  sort((v).begin(), (v).end(), sort_by_known);
  int last_place = 1;
  int p1 = 1;
  for (int i = n - 2; i >= 0; i--) {
    while (p1 < n and sort_by_known(make_pair(v[i].first + b[p1], v[i].second),
                                    make_pair(p + b[0], vas))) {
      p1++;
    }
    if (p1 >= n) break;
    p1++;
    last_place++;
  }
  int best_place = n;
  p1 = n - 2;
  for (int i = 0; i < n - 1; i++) {
    while (p1 >= 0 and
           sort_by_known(make_pair(p + b[n - 1], vas),
                         make_pair(v[i].first + b[p1], v[i].second))) {
      p1--;
    }
    if (p1 < 0) break;
    p1--;
    best_place--;
  }
  cout << (best_place) << " " << (last_place) << "\n";
  return 0;
}
