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;
const long long mod = 1000000007;
const long long INF = mod * mod;
const double eps = 1e-8;
const double pi = acos(-1.0);
map<string, int> mp;
map<pair<int, int>, vector<pair<pair<int, int>, int>>> G;
map<pair<int, int>, int> dist, rdist;
map<pair<int, int>, bool> visited, rvisited;
map<pair<int, int>, int> tnum;
map<pair<int, int>, bool> tvisited;
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
               greater<pair<int, pair<int, int>>>>
    q;
void solve() {
  int n, t;
  cin >> n >> t;
  string a, b;
  cin >> a >> b;
  mp[a] = 1, mp[b] = 2;
  int cur = 3;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    vector<int> ids;
    for (int j = 0; j < l; j++) {
      string u;
      cin >> u;
      if (!mp[u]) {
        mp[u] = cur;
        cur++;
      }
      ids.push_back(mp[u]);
    }
    for (int j = 0; j < l - 1; j++) {
      int c;
      cin >> c;
      G[{ids[j], i}].push_back({{ids[j + 1], i}, c});
      G[{ids[j + 1], i}].push_back({{ids[j], i}, c});
    }
    for (int j = 0; j < l; j++) {
      G[{ids[j], i}].push_back({{ids[j], -1}, t});
      G[{ids[j], -1}].push_back({{ids[j], i}, 0});
    }
  }
  visited[{1, -1}] = true;
  dist[{1, -1}] = 0;
  q.push({0, {1, -1}});
  while (!q.empty()) {
    pair<int, pair<int, int>> p = q.top();
    q.pop();
    if (p.first > dist[p.second]) continue;
    vector<pair<pair<int, int>, int>> &g = G[p.second];
    for (int j = 0; j < g.size(); j++) {
      pair<int, int> to = g[j].first;
      int nd = p.first + g[j].second;
      if (!visited[to]) {
        visited[to] = true;
        dist[to] = mod;
      }
      if (nd < dist[to]) {
        dist[to] = nd;
        q.push({nd, to});
      }
    }
  }
  if (!visited[{2, -1}]) {
    cout << -1 << endl;
    return;
  }
  rvisited[{2, -1}] = true;
  rdist[{2, -1}] = 0;
  q.push({0, {2, -1}});
  while (!q.empty()) {
    pair<int, pair<int, int>> p = q.top();
    q.pop();
    if (p.first > rdist[p.second]) continue;
    vector<pair<pair<int, int>, int>> &g = G[p.second];
    for (int j = 0; j < g.size(); j++) {
      pair<int, int> to = g[j].first;
      int nd = p.first + g[j].second;
      if (!rvisited[to]) {
        rvisited[to] = true;
        rdist[to] = mod;
      }
      if (nd < rdist[to]) {
        rdist[to] = nd;
        q.push({nd, to});
      }
    }
  }
  int ma = dist[{2, -1}] - t;
  tnum[{1, -1}] = 0;
  tvisited[{1, -1}] = true;
  q.push({0, {1, -1}});
  while (!q.empty()) {
    pair<int, pair<int, int>> p = q.top();
    q.pop();
    if (p.first > tnum[p.second]) continue;
    vector<pair<pair<int, int>, int>> &g = G[p.second];
    for (int j = 0; j < g.size(); j++) {
      pair<int, int> to = g[j].first;
      int hantei = ma;
      if (to.second == -1) hantei += t;
      if (dist[p.second] + rdist[to] + g[j].second != hantei) continue;
      int cost = 0;
      if (p.second.second != to.second) cost = 1;
      int nd = p.first + cost;
      if (!tvisited[to]) {
        tvisited[to] = true;
        tnum[to] = mod;
      }
      if (nd < tnum[to]) {
        tnum[to] = nd;
        q.push({nd, to});
      }
    }
  }
  int mi = tnum[{2, -1}];
  mi = mi / 2 - 1;
  cout << ma << " " << mi << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
