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 P {
  int cost;
  int node;
  int trans;
  int kind;
  bool operator<(const P& another) const {
    if (cost != another.cost) {
      return cost > another.cost;
    } else {
      return trans < another.trans;
    }
  }
};
struct edge {
  int kind;
  int to;
  int cost;
  bool operator<(const edge& another) const { return cost < another.cost; }
};
const int MAX_N = 100005;
int d[MAX_N];
int tr[MAX_N];
vector<edge> G[MAX_N];
int n, t;
void dijkstra(int s) {
  priority_queue<P> que;
  d[s] = 0;
  que.push((P){0, s, 0, 0});
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.node;
    if (d[v] < p.cost) continue;
    vector<edge>::iterator it = G[v].begin();
    for (int i = 0; i < (int)(G[v].size()); ++i) {
      int ntr;
      bool flag = (p.kind == 0 || p.kind == G[v][i].kind);
      if (flag) {
        ntr = p.trans;
      } else {
        ntr = p.trans + 1;
      }
      if (d[G[v][i].to] > d[v] + G[v][i].cost + (flag ? 0 : t)) {
        d[G[v][i].to] = d[v] + G[v][i].cost + (flag ? 0 : t);
        tr[G[v][i].to] = ntr;
        que.push((P){d[G[v][i].to], G[v][i].to, tr[G[v][i].to], G[v][i].kind});
      } else if (d[G[v][i].to] == d[v] + G[v][i].cost + (flag ? 0 : t) &&
                 tr[G[v][i].to] > ntr) {
        tr[G[v][i].to] = ntr;
        que.push((P){d[G[v][i].to], G[v][i].to, tr[G[v][i].to], G[v][i].kind});
      }
    }
  }
}
int main() {
  int cnt = 1;
  map<string, int> mp;
  cin >> n >> t;
  string s1, s2;
  cin >> s1 >> s2;
  mp[s1] = cnt++, mp[s2] = cnt++;
  for (int i = 0; i < (int)(n); ++i) {
    int a;
    cin >> a;
    vector<int> vec(a);
    for (int j = 0; j < (int)(a); ++j) {
      string s;
      cin >> s;
      if (mp[s] == 0) {
        vec[j] = cnt;
        mp[s] = cnt++;
      } else {
        vec[j] = mp[s];
      }
    }
    for (int j = 0; j < (int)(a - 1); ++j) {
      int tm;
      cin >> tm;
      G[vec[j]].push_back((edge){i + 1, vec[j + 1], tm});
      G[vec[j + 1]].push_back((edge){i + 1, vec[j], tm});
    }
  }
  fill(d, d + cnt, 1000000005);
  fill(tr, tr + cnt, 1000000005);
  dijkstra(1);
  if (d[2] >= 1000000005) {
    cout << "-1\n";
  } else {
    cout << d[2] << " " << tr[2] << "\n";
  }
  return 0;
}
