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;
map<pair<int, string>, int> M;
int id(int line, string sta) {
  if (M.find(make_pair(line, sta)) == M.end()) {
    int id = M.size();
    M[make_pair(line, sta)] = id;
  }
  return M[make_pair(line, sta)];
}
typedef tuple<int, int, int> T3;
vector<T3> E[200000];
int main() {
  int N, T;
  cin >> N >> T;
  string A, B;
  cin >> A >> B;
  int start = id(0, A), goal = id(0, B);
  for (int n = 1; n <= N; n++) {
    int a;
    cin >> a;
    vector<string> S(a);
    vector<int> TT(a - 1);
    for (auto &s : S) {
      cin >> s;
    }
    for (auto &t : TT) {
      cin >> t;
    }
    for (auto s : S) {
      int ground = id(0, s);
      int inside = id(n, s);
      E[ground].emplace_back(inside, T, 1);
      E[inside].emplace_back(ground, 0, 0);
    }
    for (int i = 0; i < a - 1; i++) {
      int cs = id(n, S[i]);
      int ns = id(n, S[i + 1]);
      E[cs].emplace_back(ns, TT[i], 0);
      E[ns].emplace_back(cs, TT[i], 0);
    }
  }
  priority_queue<T3, vector<T3>, greater<T3>> que;
  que.emplace(0, 0, start);
  typedef pair<int, int> P;
  vector<P> memo(200000, P(1000000000, 0));
  while (!que.empty()) {
    int time, transfer, cs;
    tie(time, transfer, cs) = que.top();
    que.pop();
    if (cs == goal) {
      cout << time - T << ' ' << transfer - 1 << endl;
      return 0;
    }
    for (auto e : E[cs]) {
      int to, dist, trans;
      tie(to, dist, trans) = e;
      if (P(dist + time, transfer + trans) < memo[to]) {
        memo[to] = P(dist + time, transfer + trans);
        que.emplace(dist + time, transfer + trans, to);
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
