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>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T>
using Table = vector<vector<T>>;
struct Edge {
  int from;
  int to;
  int cost;
  int line;
};
struct Node {
  int num;
  vector<Edge> es;
};
struct aa {
  int place;
  int line;
  int time;
  int change;
};
class Compare {
 public:
  bool operator()(const aa& l, const aa& r) {
    return l.time == r.time ? l.change < r.change : l.time < r.time;
  }
};
int main() {
  int N;
  cin >> N;
  vector<vector<Edge>> edges(100000);
  int T;
  cin >> T;
  map<string, int> names;
  vector<vector<int>> sames(50000);
  string A, B;
  cin >> A >> B;
  names[A] = 0;
  names[B] = 1;
  int num = 1;
  int id = 0;
  for (int l = 0; l < N; ++l) {
    int a;
    cin >> a;
    vector<int> stations;
    for (int i = 0; i < a; ++i) {
      string name;
      cin >> name;
      int now;
      if (names.find(name) == names.end()) {
        num++;
        names[name] = num;
      }
      now = names[name];
      sames[now].push_back(id);
      id++;
    }
    vector<int> times;
    for (int i = 0; i < a - 1; ++i) {
      int time;
      cin >> time;
      times.push_back(time);
    }
    for (int i = 0; i < a - 1; ++i) {
      edges[id - a + i].push_back(
          Edge{id - a + i, id - a + i + 1, times[i], l});
      edges[id - a + i + 1].push_back(
          Edge{id - a + i + 1, id - a + i, times[i], l});
    }
  }
  for (int i = 0; i < sames.size(); ++i) {
    for (int j = 0; j < int(sames[i].size()) - 1; ++j) {
      edges[sames[i][j]].push_back(Edge{sames[i][j], sames[i][j + 1], T, -1});
      edges[sames[i][j + 1]].push_back(
          Edge{sames[i][j + 1], sames[i][j], T, -1});
    }
  }
  vector<pair<int, int>> memos(100000, make_pair(1e9, 0));
  const int start = sames[0][0];
  vector<int> goals;
  for (int i = 0; i < sames[1].size(); ++i) {
    goals.push_back(sames[1][i]);
  }
  memos[start] = make_pair(0, 0);
  priority_queue<aa, vector<aa>, Compare> que;
  que.push(aa{start, 1000000, 0, 0});
  int ans = -1;
  int c = 0;
  while (!que.empty()) {
    aa atop(que.top());
    que.pop();
    int now = atop.place;
    int ntime = atop.time;
    int nchange = atop.change;
    const int nline = atop.line;
    if (find(goals.begin(), goals.end(), now) != goals.end()) {
      ans = ntime;
      c = nchange;
      break;
    }
    for (auto e : edges[now]) {
      int next = e.to;
      int nexttime = ntime;
      int nextchange = nchange;
      if (nline == -1 && e.line == -1) {
      } else if (e.line == nline) {
        nexttime += e.cost;
      } else {
        nexttime += e.cost;
        if (e.line == -1) nextchange++;
      }
      if (memos[next] > make_pair(nexttime, nextchange)) {
        memos[next] = make_pair(nexttime, nextchange);
        que.push(aa{next, e.line, nexttime, nextchange});
      }
    }
  }
  if (ans == -1) {
    cout << -1 << endl;
  } else {
    cout << ans << " " << c << endl;
  }
  return 0;
}
