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;
template <typename T>
class IdMap {
 public:
  IdMap(int n = 0) : ridx(n) { ; }
  void add(const T t) {
    _idx[t] = ridx.size();
    ridx.push_back(t);
  }
  int idx(const T &t) {
    if (_idx.find(t) == _idx.end()) add(t);
    return _idx[t];
  }
  T get(int i) { return ridx[i]; }

 private:
  map<T, int> _idx;
  vector<T> ridx;
};
struct Edge {
  int s, t, c;
};
bool operator<(const Edge &e, const Edge &f) {
  return e.c != f.c ? e.c > f.c : e.s < f.s;
}
vector<int> seg[100001];
vector<int> ridx;
int tr;
int spath(const vector<vector<Edge> > &g, int s, int t, IdMap<string> &id) {
  const int n = g.size();
  vector<int> dist(n, inf), prev(n, -1), sw(n, inf);
  priority_queue<Edge> q;
  for (int i = 0; i < seg[s].size(); ++i) {
    q.push((Edge){-2, seg[s][i], 0});
    dist[seg[s][i]] = 0;
    sw[seg[s][i]] = 0;
  }
  while (!q.empty()) {
    Edge e = q.top();
    q.pop();
    if (dist[e.t] < e.c) continue;
    for (int i = 0; i < (int)g[e.t].size(); ++i) {
      int v = g[e.t][i].t, c = g[e.t][i].c;
      if (dist[v] > e.c + c || (dist[v] == e.c + c && sw[v] > sw[e.t])) {
        dist[v] = e.c + c;
        sw[v] = sw[e.t];
        q.push((Edge){e.t, v, c + e.c});
      }
    }
    int nm = ridx[e.t];
    for (int i = 0; i < (int)seg[nm].size(); ++i) {
      int v = seg[nm][i];
      if (v == e.t) continue;
      if (dist[v] > e.c + t || (dist[v] == e.c + t && sw[v] > sw[e.t] + 1)) {
        dist[v] = e.c + tr;
        sw[v] = sw[e.t] + 1;
        q.push((Edge){e.t, v, tr + e.c});
      }
    }
  }
  int ans = inf, aw;
  for (int i = 0; i < seg[t].size(); ++i)
    if (ans > dist[seg[t][i]] ||
        (ans == dist[seg[t][i]] && aw < sw[seg[t][i]])) {
      ans = dist[seg[t][i]];
      aw = sw[seg[t][i]];
    }
  if (ans == inf) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << " " << aw << endl;
  return ans;
}
int main() {
  int n, a;
  string A, B, in;
  for (int i = 0; i < (int)100001; ++i) seg[i] = vector<int>(0);
  cin >> n >> tr >> A >> B;
  vector<vector<Edge> > g;
  IdMap<string> id;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    vector<int> s(a), time(a);
    for (int j = 0; j < a; ++j) {
      cin >> in;
      s[j] = id.idx(in);
      ridx.push_back(s[j]);
    }
    seg[s[0]].push_back(cnt);
    g.push_back(vector<Edge>(0));
    cnt++;
    for (int j = 0; j < a - 1; ++j) {
      cin >> time[j + 1];
      seg[s[j + 1]].push_back(cnt);
      g.push_back(vector<Edge>(0));
      g[cnt - 1].push_back((Edge){cnt - 1, cnt, time[j + 1]});
      g[cnt].push_back((Edge){cnt, cnt - 1, time[j + 1]});
      cnt++;
    }
  }
  spath(g, id.idx(A), id.idx(B), id);
}
