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, m, T;
vector<pair<pair<int, int>, pair<int, int> > > G[100001];
set<pair<pair<int, int>, pair<int, int> > > S;
pair<pair<int, int>, pair<int, int> > pp(int a, int b, int c, int d) {
  return pair<pair<int, int>, pair<int, int> >(pair<int, int>(a, b),
                                               pair<int, int>(c, d));
}
pair<int, int> dijkstra(int second, int g) {
  vector<pair<int, int> > D(n, pair<int, int>((1e9), (1e9)));
  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;
  Q.push(pp(0, 0, second, -1));
  while (!Q.empty()) {
    pair<pair<int, int>, pair<int, int> > t = Q.top();
    Q.pop();
    int cost = t.first.first, num = t.first.second;
    int pos = t.second.first, c = t.second.second;
    if (D[pos] < pair<int, int>(cost, num)) continue;
    if (pos == g) return pair<int, int>(cost, num);
    for (int i = 0; i < G[pos].size(); i++) {
      int ncost = cost + G[pos][i].first.second;
      int nnum = num;
      int to = G[pos][i].first.first;
      int nc = G[pos][i].second.first;
      if (c != -1 && (c != nc || !S.count(pp(pos, to, nc, -1))))
        ncost += T, nnum++;
      if (D[to] > pair<int, int>(ncost, nnum))
        Q.push(pp(ncost, nnum, to, nc)), D[to] = pair<int, int>(ncost, nnum);
    }
  }
  return pair<int, int>(-1, -1);
}
map<string, int> mp;
void add_edge(vector<string> &str, vector<int> &cost, int idx) {
  int pre, pos;
  mp.count(str[0]) ? pre = mp[str[0]] : pre = mp[str[0]] = n++;
  for (int j = 0; j < cost.size(); j++) {
    mp.count(str[j + 1]) ? pos = mp[str[j + 1]] : pos = mp[str[j + 1]] = n++;
    S.insert(pp(pos, pre, idx, -1));
    S.insert(pp(pre, pos, idx, -1));
    G[pre].push_back(pp(pos, cost[j], idx, -1));
    G[pos].push_back(pp(pre, cost[j], idx, -1));
    pre = pos;
  }
}
int main() {
  string second, g;
  cin >> m >> T >> second >> g;
  mp[second] = n++, mp[g] = n++;
  for (int i = 0, a; i < m; i++) {
    cin >> a;
    vector<string> str(a);
    vector<int> cost(a - 1);
    for (int j = 0; j < a; j++) cin >> str[j];
    for (int j = 0; j < a - 1; j++) cin >> cost[j];
    add_edge(str, cost, i);
  }
  pair<int, int> ans = dijkstra(0, 1);
  if (ans == pair<int, int>(-1, -1))
    cout << -1 << endl;
  else
    cout << ans.first << " " << ans.second << endl;
  return 0;
}
