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[100005];
pair<int, int> d[100005];
int v[100005], w;
edge p[100005];
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;
      G[v[j]].push_back((edge){v[j + 1], w, i, cnt});
      p[cnt++] = G[v[j]].back();
      G[v[j + 1]].push_back((edge){v[j], w, i, cnt});
      p[cnt++] = G[v[j + 1]].back();
    }
  }
  fill(d, d + 100005, pair<int, int>(1e9, 1e9));
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      Q;
  for (int i = 0; i < (int)G[si].size(); i++) {
    edge e = G[si][i];
    if (pair<int, int>(e.cost, 0) < d[e.id]) {
      d[e.id] = pair<int, int>(e.cost, 0);
      Q.push(pair<pair<int, int>, int>(pair<int, int>(e.cost, 0), e.id));
    }
  }
  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 = p[q.second].to;
    int type = p[q.second].type;
    if (pos == ti) {
      ans = cost;
      break;
    }
    for (int i = 0; i < (int)G[pos].size(); i++) {
      edge e = G[pos][i];
      pair<int, int> ncost = cost;
      ncost.first += e.cost;
      if (e.type != type) ncost.first += T, ncost.second++;
      if (ncost < d[e.id]) {
        d[e.id] = ncost;
        Q.push(pair<pair<int, int>, int>(ncost, e.id));
      }
    }
  }
  if (ans.first == -1)
    cout << -1 << endl;
  else
    cout << ans.first << ' ' << ans.second << endl;
  return 0;
}
