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;
struct S {
  int v, l, o, t, n;
  bool operator<(S s) const { return (t != s.t) ? t > s.t : n > s.n; }
};
struct edge {
  int v, t;
};
vector<string> names;
set<int> lines[123456];
map<int, vector<edge> > G[123456];
set<int> u[123456][2];
vector<string> s[52345];
vector<int> t[52345];
int to_num(string s) {
  return lower_bound(begin(names), end(names), s) - begin(names);
}
int main() {
  int N, T;
  cin >> N >> T;
  string A, B;
  cin >> A >> B;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    s[i].resize(a);
    for (int j = 0; j < a; j++) {
      cin >> s[i][j];
      names.push_back(s[i][j]);
    }
    t[i].resize(a - 1);
    for (int j = 0; j < a - 1; j++) {
      cin >> t[i][j];
    }
  }
  sort(begin(names), end(names));
  names.erase(unique(begin(names), end(names)), end(names));
  for (int i = 0; i < N; i++) {
    for (auto e : s[i]) {
      lines[to_num(e)].insert(i);
    }
    for (int j = 0; j < t[i].size(); j++) {
      int from = to_num(s[i][j]), to = to_num(s[i][j + 1]);
      G[from][i].push_back({to, t[i][j]});
      G[to][i].push_back({from, t[i][j]});
    }
  }
  priority_queue<S> que;
  que.push({to_num(A), *lines[to_num(A)].begin(), 1, 0, 0});
  while (!que.empty()) {
    auto c = que.top();
    if (c.v == to_num(B)) break;
    que.pop();
    if (!u[c.v][c.o].insert(c.l).second) continue;
    if (c.o) {
      que.push({c.v, c.l, 0, c.t, c.n});
      auto it = lines[c.v].lower_bound(c.l);
      if (it != lines[c.v].begin()) {
        auto fit = it;
        que.push({c.v, *--fit, 1, c.t, c.n});
      }
      auto bit = it;
      if (++bit != lines[c.v].end()) {
        que.push({c.v, *bit, 1, c.t, c.n});
      }
    } else {
      for (auto e : G[c.v][c.l]) {
        que.push({e.v, c.l, 0, c.t + e.t, c.n});
      }
      que.push({c.v, c.l, 1, c.t + T, c.n + 1});
    }
  }
  if (que.empty()) {
    cout << -1 << endl;
  } else {
    cout << que.top().t << ' ' << que.top().n << endl;
  }
}
