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 ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
struct edge {
  int to;
  ll cost;
  int trans;
};
const int N = 200000;
const ll INF = LLONG_MAX / 3;
using pl = pair<ll, int>;
vector<edge> G[N];
pl d[N];
int main() {
  int n, T;
  string start, goal;
  cin >> n >> T >> start >> goal;
  map<string, int> s2id;
  int num = 0;
  s2id[start] = num++;
  s2id[goal] = num++;
  vector<int> a(n);
  vector<vector<int>> r(n), t(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    cin >> a[i];
    r[i] = vector<int>(a[i]);
    t[i] = vector<int>(a[i] - 1);
    for (int(j) = 0; (j) < (int)(a[i]); ++(j)) {
      string tmp;
      cin >> tmp;
      if (!s2id.count(tmp)) s2id[tmp] = num++;
      r[i][j] = s2id[tmp];
    }
    for (int(j) = 0; (j) < (int)(a[i] - 1); ++(j)) cin >> t[i][j];
  }
  map<pair<int, int>, int> p2id;
  int SZ = 0;
  for (int(i) = 0; (i) < (int)(num); ++(i)) p2id[{i, -1}] = SZ++;
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    for (int(j) = 0; (j) < (int)(a[i]); ++(j)) {
      if (!p2id.count({r[i][j], i})) p2id[{r[i][j], i}] = SZ++;
      int u = p2id[{r[i][j], i}], v = p2id[{r[i][j], -1}];
      if (r[i][j] == 1)
        G[u].push_back({v, 0, 0});
      else
        G[u].push_back({v, T, 1});
      G[v].push_back({u, 0, 0});
    }
    for (int(j) = 0; (j) < (int)(a[i] - 1); ++(j)) {
      int u = p2id[{r[i][j], i}], v = p2id[{r[i][j + 1], i}];
      G[u].push_back({v, t[i][j], 0});
      G[v].push_back({u, t[i][j], 0});
    }
  }
  fill(d, d + N, pl(INF, N));
  using P = pair<pl, int>;
  priority_queue<P, vector<P>, greater<P>> pq;
  d[p2id[{0, -1}]] = {0, 0};
  pq.push({{0, 0}, p2id[{0, -1}]});
  while (!pq.empty()) {
    P now = pq.top();
    pq.pop();
    int v = now.second;
    if (now.first > d[v]) continue;
    for (const auto& e : G[v]) {
      pl nx = now.first;
      nx.first += e.cost;
      nx.second += e.trans;
      if (d[e.to] > nx) {
        d[e.to] = nx;
        pq.push({nx, e.to});
      }
    }
  }
  pl ans = d[p2id[{1, -1}]];
  if (ans.first == INF)
    cout << -1 << endl;
  else
    cout << ans.first << " " << ans.second << endl;
  return 0;
}
