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;
vector<string> S;
vector<string> T;
string U, V, W;
int n, t, p, q, st, en;
vector<string> R[80000];
vector<int> B[80000];
vector<int> C[80000];
int color[80000];
pair<int, int> d[80000];
vector<pair<int, int>> X[80000];
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
               greater<tuple<int, int, int>>>
    Q;
pair<int, int> dijkstra(int P1, int Q1) {
  for (int i = 0; i < 80000; i++) {
    color[i] = 0;
    d[i] = make_pair(1145141919, 1145141919);
  }
  color[P1] = 1;
  d[P1] = make_pair(0, 0);
  Q.push(make_tuple(0, 0, P1));
  while (!Q.empty()) {
    tuple<int, int, int> f = Q.top();
    int A = get<0>(f);
    int C = get<1>(f);
    int B = get<2>(f);
    Q.pop();
    color[B] = 2;
    if (d[B].first < A * (-1)) continue;
    for (int v = 0; v < X[B].size(); v++) {
      int w = X[B][v].first;
      int z = X[B][v].second;
      if (color[w] == 2) continue;
      if (d[w].second > d[B].first + z && d[w].second > d[B].second + 1) {
        d[w] = make_pair(d[B].first + z, d[B].second + 1);
        Q.push(make_tuple(d[w].first, d[w].second, w));
        color[w] = 1;
      }
    }
  }
  return d[Q1];
}
int main() {
  cin >> n >> t;
  cin >> U >> V;
  for (int i = 0; i < n; i++) {
    cin >> p;
    for (int j = 0; j < p; j++) {
      cin >> W;
      R[i].push_back(W);
      S.push_back(W);
    }
    for (int j = 0; j < p - 1; j++) {
      cin >> q;
      if (j == 0) {
        C[i].push_back(q);
      }
      if (j >= 1) {
        C[i].push_back(q + C[i][j - 1]);
      }
    }
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < S.size(); i++) {
    if (i == 0) {
      T.push_back(S[i]);
    } else {
      if (S[i - 1] != S[i]) {
        T.push_back(S[i]);
      }
    }
  }
  st = upper_bound(T.begin(), T.end(), U) - T.begin();
  en = upper_bound(T.begin(), T.end(), V) - T.begin();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < R[i].size(); j++) {
      B[i].push_back(upper_bound(T.begin(), T.end(), R[i][j]) - T.begin());
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < B[i].size(); j++) {
      for (int k = j + 1; k < B[i].size(); k++) {
        if (j == 0) {
          X[B[i][j]].push_back(make_pair(B[i][k], C[i][k - 1] + t));
          X[B[i][k]].push_back(make_pair(B[i][j], C[i][k - 1] + t));
        }
        if (j >= 1) {
          X[B[i][j]].push_back(
              make_pair(B[i][k], C[i][k - 1] - C[i][j - 1] + t));
          X[B[i][k]].push_back(
              make_pair(B[i][j], C[i][k - 1] - C[i][j - 1] + t));
        }
      }
    }
  }
  pair<int, int> r = dijkstra(st, en);
  if (r.first >= 1145141919) {
    cout << "-1" << endl;
  } else {
    cout << r.first - t << ' ' << r.second - 1 << endl;
  }
  return 0;
}
