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;
using pii = pair<int, int>;
using Edge = tuple<int, int, int>;
constexpr int MAX = 100000;
constexpr int INF = (1 << 29);
struct State {
  int v, cost, trans, line;
  State() {}
  State(int v, int cost, int trans, int line)
      : v{v}, cost{cost}, trans{trans}, line{line} {}
  bool operator<(const State& s) const {
    if (cost != s.cost) {
      return cost > s.cost;
    }
    return trans > s.trans;
  }
};
int N, T, n;
vector<Edge> G[MAX];
pii dijkstra(const vector<int>& init_lines) {
  vector<pii> d(n, pii(INF, INF));
  d[0] = pii(0, 0);
  priority_queue<State> pq;
  for (auto& l : init_lines) {
    pq.push(State(0, 0, 0, l));
  }
  while (!pq.empty()) {
    State st = pq.top();
    pq.pop();
    int v = st.v, cost = st.cost, trans = st.trans, line = st.line;
    if (v == 1) return d[v];
    for (const auto& g : G[v]) {
      int to = get<0>(g);
      int ncost = cost + get<1>(g) + (line != get<2>(g) ? T : 0);
      int ntrans = trans + (line != get<2>(g));
      if (pii(ncost, ntrans) < d[to]) {
        d[to] = pii(ncost, ntrans);
        pq.push(State(to, ncost, ntrans, get<2>(g)));
      }
    }
  }
  return pii(-1, -1);
}
int main() {
  string A, B;
  map<string, int> s2i;
  vector<int> init_lines;
  cin >> N >> T >> A >> B;
  s2i[A] = 0;
  s2i[B] = 1;
  int cur = 2;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    vector<int> v;
    for (int j = 0; j < a; j++) {
      string s;
      cin >> s;
      if (s2i.count(s) == 0) {
        s2i[s] = cur++;
      }
      if (s2i[s] == 0 && a >= 2) {
        init_lines.emplace_back(i);
      }
      v.emplace_back(s2i[s]);
    }
    for (int j = 0; j < a - 1; j++) {
      int cost;
      cin >> cost;
      G[v[j]].emplace_back(v[j + 1], cost, i);
      G[v[j + 1]].emplace_back(v[j], cost, i);
    }
  }
  n = cur;
  pii res = dijkstra(init_lines);
  if (res.first == -1) {
    cout << -1 << endl;
  } else {
    cout << res.first << " " << res.second << endl;
  }
  return 0;
}
