Example

Input

2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
3
Moscow Minsk Warsaw
100 150


Output

380 1
#include <bits/stdc++.h>
using namespace std;
class edge {
 public:
  int to, cost;
  bool b;
  edge(int to, int cost, bool b) : to(to), cost(cost), b(b) {}
};
class State {
 public:
  int n, cost, sum;
  State(int n, int cost, int sum) : n(n), cost(cost), sum(sum) {}
  bool operator<(State second) const {
    if (cost != second.cost) return second.cost < cost;
    return second.sum < sum;
  }
};
vector<edge> v[200001];
int n, t;
map<string, vector<int> > m;
string a, b;
set<int> st;
void add(int c, string second) {
  vector<int> vi = m[second];
  for (int i = 0; i < vi.size(); i++) {
    v[vi[i]].push_back(edge(c, t, true));
    v[c].push_back(edge(vi[i], t, true));
  }
  vi.push_back(c);
  m[second] = vi;
}
pair<int, int> dijkstra() {
  pair<int, int> dis[200001];
  for (int i = 0; i < 200001; i++) {
    dis[i].first = 1 << 28;
    dis[i].second = 1 << 28;
  }
  vector<int> start = m[a];
  vector<int> end = m[b];
  for (int i = 0; i < end.size(); i++) st.insert(end[i]);
  priority_queue<State> pq;
  for (int i = 0; i < start.size(); i++) {
    pq.push(State(start[i], 0, 0));
    dis[start[i]] = make_pair(0, 0);
  }
  while (!pq.empty()) {
    State u = pq.top();
    pq.pop();
    if (st.find(u.n) != st.end()) return make_pair(u.cost, u.sum);
    if (dis[u.n] < make_pair(u.cost, u.sum)) continue;
    for (int i = 0; i < v[u.n].size(); i++) {
      int next = v[u.n][i].to, cost = v[u.n][i].cost;
      bool first = v[u.n][i].b;
      if (make_pair(dis[u.n].first + cost, dis[u.n].second + first) <
          dis[next]) {
        dis[next] = make_pair(dis[u.n].first + cost, dis[u.n].second + first);
        pq.push(State(next, dis[next].first, dis[next].second));
      }
    }
  }
  return make_pair(-1, -1);
}
int main() {
  int k, c[200001], count = 0;
  string second[200001];
  cin >> n >> t;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) cin >> second[j];
    for (int j = 0; j < k - 1; j++) cin >> c[j];
    for (int j = 0; j < k - 1; j++) {
      add(count, second[j]);
      v[count].push_back(edge(count + 1, c[j], false));
      v[count + 1].push_back(edge(count, c[j], false));
      count++;
    }
    add(count, second[k - 1]);
    count++;
  }
  pair<int, int> p = dijkstra();
  if (p == make_pair(-1, -1))
    cout << -1 << endl;
  else
    cout << p.first << " " << p.second << endl;
  return 0;
}
