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;
const int INF = 1 << 29;
pair<int, int> operator-(const pair<int, int> &a) {
  return make_pair(-a.first, -a.second);
}
int main() {
  map<string, int> f;
  int n, T;
  scanf("%d%d", &n, &T);
  char tmp[16];
  scanf("%s", tmp);
  if (f.count(tmp) == 0) f.insert(make_pair(tmp, f.size()));
  int s = f[tmp];
  scanf("%s", tmp);
  if (f.count(tmp) == 0) f.insert(make_pair(tmp, f.size()));
  int g = f[tmp];
  int N = 0;
  static int idx1[100000], idx2[100000];
  static vector<int> route[50000], t[50000];
  for (int i = 0; i < (n); i++) {
    int m;
    scanf("%d", &m);
    route[i].resize(m);
    t[i].resize(m - 1);
    for (int j = 0; j < (m); j++) {
      scanf("%s", tmp);
      if (f.count(tmp) == 0) f.insert(make_pair(tmp, f.size()));
      route[i][j] = f[tmp];
      idx1[N] = i;
      idx2[N] = j;
      N++;
    }
    for (int j = 0; j < (m - 1); j++) {
      scanf("%d", &t[i][j]);
    }
  }
  static vector<int> V[100000];
  for (int u = 0; u < (N); u++) V[route[idx1[u]][idx2[u]]].push_back(u);
  static pair<int, int> d[100000][2];
  for (int u = 0; u < (N); u++)
    for (int dir = 0; dir < (2); dir++) d[u][dir].first = INF;
  pair<int, int> ans(-1, 0);
  priority_queue<pair<pair<int, int>, pair<int, int> > > Q;
  for (int u = 0; u < (N); u++)
    if (route[idx1[u]][idx2[u]] == s) {
      d[u][0] = d[u][1] = make_pair(0, 0);
      Q.push(make_pair(make_pair(0, 0), make_pair(u, 0)));
      Q.push(make_pair(make_pair(0, 0), make_pair(u, 1)));
    }
  while (!Q.empty()) {
    pair<int, int> d_now = -Q.top().first;
    int u = Q.top().second.first, dir = Q.top().second.second;
    Q.pop();
    if (d[u][dir] < d_now) continue;
    if (route[idx1[u]][idx2[u]] == g) {
      ans = d_now;
      break;
    }
    if (dir == 0) {
      if (idx2[u] + 1 < route[idx1[u]].size()) {
        pair<int, int> d_next = d_now;
        d_next.first += t[idx1[u]][idx2[u]];
        if (d[u + 1][dir] > d_next) {
          d[u + 1][dir] = d_next;
          Q.push(make_pair(-d_next, make_pair(u + 1, dir)));
        }
      }
    } else {
      if (idx2[u] - 1 >= 0) {
        pair<int, int> d_next = d_now;
        d_next.first += t[idx1[u]][idx2[u] - 1];
        if (d[u - 1][dir] > d_next) {
          d[u - 1][dir] = d_next;
          Q.push(make_pair(-d_next, make_pair(u - 1, dir)));
        }
      }
    }
    for (int i = 0; i < (V[route[idx1[u]][idx2[u]]].size()); i++) {
      int v = V[route[idx1[u]][idx2[u]]][i];
      pair<int, int> d_next = d_now;
      d_next.first += T;
      d_next.second++;
      for (int dir2 = 0; dir2 < (2); dir2++) {
        if (d[v][dir2] > d_next) {
          d[v][dir2] = d_next;
          Q.push(make_pair(-d_next, make_pair(v, dir2)));
        }
      }
    }
  }
  if (ans.first == -1)
    puts("-1");
  else
    printf("%d %d\n", ans.first, ans.second);
  return 0;
}
