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 int MOD = 1000000007;
const long long INF = LLONG_MAX / 10;
const long double EPS = 1e-12;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
int n, t, src, dst, V;
map<string, int> id;
vector<vector<int>> stations;
vector<vector<int>> cost;
vector<vector<pair<int, int>>> change;
int main() {
  cin.sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string ss, sd;
  cin >> n >> t >> ss >> sd;
  id[ss] = 0;
  id[sd] = 1;
  src = 0, dst = 1;
  V = 2;
  stations.resize(n);
  cost.resize(n);
  for (int i = (int)(0); i < (int)(n); i++) {
    int a;
    cin >> a;
    for (int j = (int)(0); j < (int)(a); j++) {
      string s;
      cin >> s;
      if (!id.count(s)) {
        id[s] = V;
        V++;
        change.resize(V);
      }
      stations[i].push_back(id[s]);
      change[id[s]].emplace_back(i, j);
    }
    for (int j = (int)(0); j < (int)(a - 1); j++) {
      int t;
      cin >> t;
      cost[i].push_back(t);
    }
  }
  vector<vector<pair<long long, int>>> d(n);
  for (int i = (int)(0); i < (int)(n); i++) {
    d[i].resize(stations[i].size(), pair<long long, int>(INF, 1e9));
  }
  vector<bool> used(V);
  priority_queue<pair<pair<long long, int>, pair<int, int>>> que;
  for (auto i : change[0]) {
    d[i.first][i.second] = pair<long long, int>(0, 0);
    que.emplace(make_pair(pair<long long, int>(0, 0), i));
  }
  while (!que.empty()) {
    pair<long long, int> w = que.top().first;
    int rosen = que.top().second.first;
    int pos = que.top().second.second;
    que.pop();
    int tmp = stations[rosen][pos];
    if (d[rosen][pos] < w) continue;
    if (pos != 0) {
      int ct = cost[rosen][pos - 1];
      if (d[rosen][pos - 1] > pair<long long, int>(d[rosen][pos].first + ct,
                                                   d[rosen][pos].second)) {
        d[rosen][pos - 1] = pair<long long, int>(d[rosen][pos].first + ct,
                                                 d[rosen][pos].second);
        que.emplace(
            make_pair(d[rosen][pos - 1], pair<int, int>(rosen, pos - 1)));
      }
    }
    if (pos != stations[rosen].size() - 1) {
      int ct = cost[rosen][pos];
      if (d[rosen][pos + 1] > pair<long long, int>(d[rosen][pos].first + ct,
                                                   d[rosen][pos].second)) {
        d[rosen][pos + 1] = pair<long long, int>(d[rosen][pos].first + ct,
                                                 d[rosen][pos].second);
        que.emplace(
            make_pair(d[rosen][pos + 1], pair<int, int>(rosen, pos + 1)));
      }
    }
    if (!used[tmp]) {
      used[tmp] = true;
      for (auto i : change[tmp]) {
        if (d[i.first][i.second] >
            pair<long long, int>(d[rosen][pos].first + t,
                                 d[rosen][pos].second + 1)) {
          d[i.first][i.second] = pair<long long, int>(d[rosen][pos].first + t,
                                                      d[rosen][pos].second + 1);
          que.emplace(make_pair(d[i.first][i.second],
                                pair<int, int>(i.first, i.second)));
        }
      }
    }
  }
  pair<long long, int> ans(INF, 1e9);
  for (auto i : change[dst]) chmin(ans, d[i.first][i.second]);
  if (ans.first >= INF)
    cout << -1 << endl;
  else
    cout << ans.first << " " << ans.second << endl;
  return 0;
}
