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;
int n, T;
unordered_map<string, int> num;
string A, B, in[100005];
int Nnum[100005];
struct dat {
  int idx, to, cost;
  dat() {}
  dat(int a, int b, int c) {
    idx = a;
    to = b;
    cost = c;
  }
};
vector<dat> G[100005];
vector<string> Node;
priority_queue<pair<pair<int, int>, pair<int, int> >,
               vector<pair<pair<int, int>, pair<int, int> > >,
               greater<pair<pair<int, int>, pair<int, int> > > >
    q;
pair<int, int> d[100005];
pair<int, int> dijkstra() {
  n = Node.size();
  for (int i = 0; i < n; i++) d[i] = pair<int, int>((1e9), (1e9));
  for (int i = 0; i < n; i++)
    if (Node[i] == A) {
      d[i] = pair<int, int>(0, 0);
      q.push(pair<pair<int, int>, pair<int, int> >(pair<int, int>(0, 0),
                                                   pair<int, int>(i, 0)));
      break;
    }
  while (!q.empty()) {
    pair<pair<int, int>, pair<int, int> > t = q.top();
    q.pop();
    int cost1 = t.first.first;
    int cost2 = t.first.second;
    int node = t.second.first;
    int flag = t.second.second;
    if (Node[node] == B) return t.first;
    if (d[node].first < cost1) continue;
    if (d[node].first == cost1 && d[node].second < cost2) continue;
    for (int i = 0; i < G[num[Node[node]]].size(); i++) {
      dat ni = G[num[Node[node]]][i];
      int ncost1 = cost1 + ni.cost;
      int ncost2 = cost2;
      int nnode = ni.to;
      int nflag = flag;
      if (ni.idx != node) ncost1 += T, ncost2++;
      if (!flag && Node[node] == A && Node[nnode] == A) {
        ncost1 = ncost2 = 0;
        nflag = 1;
      }
      if (d[nnode].first > ncost1) {
        d[nnode] = pair<int, int>(ncost1, ncost2);
        q.push(pair<pair<int, int>, pair<int, int> >(
            pair<int, int>(ncost1, ncost2), pair<int, int>(nnode, nflag)));
      }
      if (d[nnode].first == ncost1 && d[nnode].second > ncost2) {
        d[nnode] = pair<int, int>(ncost1, ncost2);
        q.push(pair<pair<int, int>, pair<int, int> >(
            pair<int, int>(ncost1, ncost2), pair<int, int>(nnode, nflag)));
      }
    }
  }
  return pair<int, int>((1e9), (1e9));
}
int main() {
  cin >> n >> T;
  cin >> A >> B;
  int cnt = 0, cnt2 = 0;
  if (!num.count(A)) num[A] = cnt++;
  if (!num.count(B)) num[B] = cnt++;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    for (int j = 0; j < a; j++) {
      Nnum[j] = cnt2++;
      cin >> in[j];
      Node.push_back(in[j]);
      if (!num.count(in[j])) num[in[j]] = cnt++;
    }
    for (int j = 0; j < a - 1; j++) {
      int t;
      scanf("%d", &t);
      G[num[in[j]]].push_back(dat(Nnum[j], Nnum[j + 1], t));
      G[num[in[j + 1]]].push_back(dat(Nnum[j + 1], Nnum[j], t));
    }
  }
  pair<int, int> ans = dijkstra();
  if (ans.first == (1e9))
    cout << -1 << endl;
  else
    cout << ans.first << " " << ans.second << endl;
  return 0;
}
