#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<string, int>> a;
string v;
vector<int> b;
bool p1(pair<string, int> a, pair<string, int> b) {
  return a.second < b.second;
}
bool cmp(pair<string, int> a, pair<string, int> b) {
  if (a.second != b.second) {
    return a.second > b.second;
  }
  return a.first < b.first;
}
int best() {
  multiset<int> can(b.begin(), b.end());
  auto job = a;
  pair<string, int> alfa;
  for (int i = 0; i < n; ++i) {
    if (job[i].first == v) {
      alfa = job[i];
      job.erase(job.begin() + i);
      break;
    }
  }
  if (m != 0) {
    alfa.second += *can.rbegin();
    can.erase(can.find(*can.rbegin()));
  }
  sort(job.begin(), job.end(), p1);
  map<string, int> del;
  for (auto &i : job) {
    if ((i.first < alfa.first && i.second >= alfa.second) ||
        i.second > alfa.second) {
      if (can.size()) {
        i.second += *can.rbegin();
        can.erase(can.find(*can.rbegin()));
      }
      del[i.first] = 1;
    }
  }
  vector<pair<string, int>> kek, ost;
  kek.push_back(alfa);
  for (auto &i : job) {
    if (del[i.first]) {
      kek.push_back(i);
    } else {
      ost.push_back(i);
    }
  }
  for (auto &i : ost) {
    if (i.first > alfa.first) {
      int value = alfa.second - i.second;
      auto it = can.upper_bound(value);
      if (it != can.begin()) {
        --it;
        del[i.first] = 1;
        i.second += (*it);
        can.erase(it);
      }
    } else {
      int value = alfa.second - i.second;
      auto it = can.lower_bound(value);
      if (it != can.begin()) {
        --it;
        del[i.first] = 1;
        i.second += (*it);
        can.erase(it);
      }
    }
  }
  for (auto &i : ost) {
    if (!del[i.first] && can.size()) {
      i.second += *can.rbegin();
      can.erase(can.find(*can.rbegin()));
    }
  }
  for (auto &i : ost) {
    kek.push_back(i);
  }
  sort(kek.begin(), kek.end(), cmp);
  for (int i = 0; i < kek.size(); ++i) {
    if (kek[i].first == v) {
      return i + 1;
    }
  }
}
int worst() {
  multiset<int> can(b.begin(), b.end());
  auto job = a;
  pair<string, int> alfa;
  for (int i = 0; i < n; ++i) {
    if (job[i].first == v) {
      alfa = job[i];
      job.erase(job.begin() + i);
      break;
    }
  }
  if (m == n && can.size()) {
    alfa.second += *can.begin();
    can.erase(can.begin());
  }
  sort(job.begin(), job.end(), p1);
  map<string, int> del;
  for (auto &i : job) {
    if ((i.first < alfa.first && i.second >= alfa.second) ||
        i.second > alfa.second) {
      del[i.first] = 1;
    }
  }
  vector<pair<string, int>> kek, ost;
  kek.push_back(alfa);
  for (auto &i : job) {
    if (del[i.first]) {
      kek.push_back(i);
    } else {
      ost.push_back(i);
    }
  }
  for (auto &i : ost) {
    if (i.first > alfa.first) {
      int value = alfa.second + 1 - i.second;
      auto it = can.lower_bound(value);
      if (it != can.end()) {
        i.second += *it;
        can.erase(it);
      }
    } else {
      int value = alfa.second - i.second;
      auto it = can.lower_bound(value);
      if (it != can.end()) {
        i.second += *it;
        can.erase(it);
      }
    }
  }
  for (auto &i : ost) {
    kek.push_back(i);
  }
  sort(kek.begin(), kek.end(), cmp);
  for (int i = 0; i < kek.size(); ++i) {
    if (kek[i].first == v) {
      return i + 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  cin >> m;
  b.resize(m);
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  cin >> v;
  cout << best() << " " << worst() << "\n";
  return 0;
}
