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;
struct edge {
  int to, cost, type, id;
};
int m, n, T, cnt, si, ti;
string str;
vector<edge> G[300005];
pair<int, int> d[300005];
int v[100005], w[100005];
edge p[200005];
map<string, int> mp;
int change(string &str) {
  if (mp.count(str))
    return mp[str];
  else
    return mp[str] = mp.size();
}
int main() {
  cin >> m >> T;
  cin >> str;
  si = change(str);
  cin >> str;
  ti = change(str);
  for (int i = 0; i < m; i++) {
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> str;
      v[j] = change(str);
    }
    for (int j = 0; j + 1 < n; j++) {
      cin >> w[j];
      G[v[j]].push_back((edge){v[j + 1], w[j], i, ++cnt});
      p[cnt] = G[v[j]].back();
    }
    for (int j = n - 2; j >= 0; j--) {
      G[v[j + 1]].push_back((edge){v[j], w[j], i, ++cnt});
      p[cnt] = G[v[j + 1]].back();
    }
  }
  int C = mp.size();
  fill(d, d + 300005, pair<int, int>(1e9, 1e9));
  d[0] = pair<int, int>(0, 0);
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      Q;
  Q.push(pair<pair<int, int>, int>(pair<int, int>(-T, -1), 1));
  pair<int, int> ans = pair<int, int>(-1, -1);
  while (!Q.empty()) {
    pair<pair<int, int>, int> q = Q.top();
    Q.pop();
    if (q.first > d[q.second]) continue;
    pair<int, int> cost = q.first;
    int pos = q.second;
    if (pos == ti) {
      ans = cost;
      break;
    }
    if (q.second <= C) {
      for (int i = 0; i < (int)G[pos].size(); i++) {
        edge e = G[pos][i];
        pair<int, int> ncost = cost;
        ncost.first += (e.cost + T);
        ncost.second++;
        if (ncost < d[e.id + C]) {
          d[e.id + C] = ncost;
          Q.push(pair<pair<int, int>, int>(ncost, e.id + C));
        }
      }
    } else {
      edge f = p[pos - C];
      if (cost < d[f.to]) {
        d[f.to] = cost;
        Q.push(pair<pair<int, int>, int>(cost, f.to));
      }
      for (int i = -1; i <= 1; i += 2) {
        if (f.id + i < 0 || cnt < f.id + i) continue;
        edge e = p[f.id + i];
        if (e.type != f.type) continue;
        pair<int, int> ncost = cost;
        ncost.first += e.cost;
        if (ncost < d[e.id + C]) {
          d[e.id + C] = ncost;
          Q.push(pair<pair<int, int>, int>(ncost, e.id + C));
        }
      }
    }
  }
  if (ans.first == -1)
    cout << -1 << endl;
  else
    cout << ans.first << ' ' << ans.second << endl;
  return 0;
}
