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<int, int> > G[100001];
set<pair<int, int> > S[100001];
vector<string> str[100001];
map<string, int> mp;
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;
  for (set<pair<int, int> >::iterator it = S[second].begin();
       it != S[second].end(); it++)
    Q.push(pair<pair<int, int>, pair<int, int> >(pair<int, int>(0, 0), *it));
  D[second] = pair<int, int>(0, 0);
  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 y = t.second.first, x = t.second.second;
    int pos = mp[str[y][x]];
    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 to = G[pos][i].first;
      for (set<pair<int, int> >::iterator j = S[to].begin(); j != S[to].end();
           j++) {
        int ncost = cost + G[pos][i].second;
        int nnum = num;
        int ny = j->first, nx = j->second;
        if (ny != y || abs(x - nx) != 1) ncost += T, nnum++;
        if (D[to] <= pair<int, int>(ncost, nnum)) continue;
        Q.push(pair<pair<int, int>, pair<int, int> >(
            pair<int, int>(ncost, nnum), pair<int, int>(ny, nx)));
        D[to] = pair<int, int>(ncost, nnum);
      }
    }
  }
  return pair<int, int>(-1, -1);
}
void add_edge(vector<int> &cost, int idx) {
  int pre, pos;
  mp.count(str[idx][0]) ? pre = mp[str[idx][0]] : pre = mp[str[idx][0]] = n++;
  S[pre].insert(pair<int, int>(idx, 0));
  for (int j = 0; j < cost.size(); j++) {
    mp.count(str[idx][j + 1]) ? pos = mp[str[idx][j + 1]]
                              : pos = mp[str[idx][j + 1]] = n++;
    S[pos].insert(pair<int, int>(idx, j + 1));
    G[pre].push_back(pair<int, int>(pos, cost[j]));
    G[pos].push_back(pair<int, int>(pre, cost[j]));
    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;
    str[i].resize(a);
    vector<int> cost(a - 1);
    for (int j = 0; j < a; j++) cin >> str[i][j];
    for (int j = 0; j < a - 1; j++) cin >> cost[j];
    add_edge(cost, i);
  }
  for (int i = 0; i < n; i++) {
    sort(G[i].begin(), G[i].end());
    for (int j = 1; j < G[i].size(); j++)
      if (G[i][j - 1] == G[i][j]) G[i].erase(G[i].begin() + j--);
  }
  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;
}
