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 sta {
  int id;
  int pos;
  pair<long long, long long> d;
};
int main() {
  int n, t;
  cin >> n >> t;
  map<string, int> mp;
  vector<vector<string>> name(n);
  vector<vector<int>> time(n);
  vector<vector<pair<int, int>>> id(n);
  string a, b;
  cin >> a >> b;
  int k;
  for (int i = 0; i < (n); i++) {
    cin >> k;
    name[i] = vector<string>(k);
    id[i] = vector<pair<int, int>>(k);
    time[i] = vector<int>(k - 1);
    for (int j = 0; j < (k); j++) {
      cin >> name[i][j];
      mp[name[i][j]] = -1;
    }
    for (int j = 0; j < (k - 1); j++) {
      cin >> time[i][j];
    }
  }
  int sn = 0;
  for (auto &p : mp) p.second = (sn++);
  int from = mp[a], to = mp[b];
  vector<int> count(sn, 0);
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (id[i].size()); j++) {
      int x = mp[name[i][j]];
      id[i][j] = {x, count[x]};
      count[x]++;
    }
  }
  vector<vector<pair<int, int>>> ro(sn);
  for (int i = 0; i < (sn); i++) {
    ro[i] = vector<pair<int, int>>(count[i]);
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (id[i].size()); j++) {
      ro[id[i][j].first][id[i][j].second] = {i, j};
    }
  }
  vector<vector<pair<long long, long long>>> dist(sn);
  for (int i = 0; i < (sn); i++) {
    dist[i] = vector<pair<long long, long long>>(
        count[i], {1000000000000000000, 1000000000000000000});
  }
  vector<bool> norikae(sn, false);
  priority_queue<sta, vector<sta>, function<bool(sta, sta)>> heap(
      [](const sta &a, const sta &b) { return a.d < b.d; });
  for (int i = 0; i < (count[from]); i++) heap.push({from, i, {0, 0}});
  pair<long long, long long> ans = {1000000000000000000, 1000000000000000000};
  while (!heap.empty()) {
    sta now = heap.top();
    heap.pop();
    if (dist[now.id][now.pos].first != 1000000000000000000) continue;
    dist[now.id][now.pos] = now.d;
    if (now.id == to) ans = min(ans, now.d);
    if (!norikae[now.id]) {
      norikae[now.id] = true;
      for (int i = 0; i < (count[now.id]); i++) {
        if (dist[now.id][i].first == 1000000000000000000)
          heap.push({now.id, i, {now.d.first + t, now.d.second + 1}});
      }
    }
    auto p = ro[now.id][now.pos];
    if (p.second > 0) {
      auto nxp = id[p.first][p.second - 1];
      long long ds = time[p.first][p.second - 1];
      if (dist[nxp.first][nxp.second].first == 1000000000000000000)
        heap.push({nxp.first, nxp.second, {now.d.first + ds, now.d.second}});
    }
    if (p.second < id[p.first].size() - 1) {
      auto nxp = id[p.first][p.second + 1];
      long long ds = time[p.first][p.second];
      if (dist[nxp.first][nxp.second].first == 1000000000000000000)
        heap.push({nxp.first, nxp.second, {now.d.first + ds, now.d.second}});
    }
  }
  if (ans.first == 1000000000000000000)
    cout << -1 << endl;
  else
    cout << ans.first << " " << ans.second << endl;
  return 0;
}
