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;
template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
int main() {
  ios::sync_with_stdio(false);
  map<string, vector<int> > lines;
  map<pair<string, int>, vector<pair<string, int> > > G;
  map<pair<string, int>, pair<int, int> > cost;
  priority_queue<pair<pair<int, int>, pair<string, int> >,
                 vector<pair<pair<int, int>, pair<string, int> > >,
                 greater<pair<pair<int, int>, pair<string, int> > > >
      que;
  int N, T;
  string A, B;
  cin >> N >> T >> A >> B;
  for (int i = (int)(0); i < (int)(N); i++) {
    int a;
    cin >> a;
    vector<string> stations(a);
    vector<int> distance(a - 1);
    for (int j = (int)(0); j < (int)(a); j++) {
      cin >> stations[j];
      lines[stations[j]].push_back(i);
    }
    for (int j = (int)(0); j < (int)(a - 1); j++) {
      cin >> distance[j];
      G[pair<string, int>(stations[j], i)].push_back(
          pair<string, int>(stations[j + 1], distance[j]));
      G[pair<string, int>(stations[j + 1], i)].push_back(
          pair<string, int>(stations[j], distance[j]));
    }
  }
  for (int line : lines[A]) {
    cost[pair<string, int>(A, line)] = pair<int, int>(0, 0);
    que.push(pair<pair<int, int>, pair<string, int> >(
        pair<int, int>(0, 0), pair<string, int>(A, line)));
  }
  while (!que.empty()) {
    pair<string, int> ps = que.top().second;
    pair<int, int> pi = que.top().first;
    que.pop();
    if (ps.first == B) {
      cout << pi.first << " " << pi.second << endl;
      exit(EXIT_SUCCESS);
    }
    if (cost[ps] < pi) {
      continue;
    }
    if (ps.second == -1) {
      for (int line : lines[ps.first]) {
        pair<string, int> nps(ps.first, line);
        auto iter = cost.find(nps);
        if (iter == cost.end() || iter->second > pi) {
          cost[nps] = pi;
          que.push(pair<pair<int, int>, pair<string, int> >(pi, nps));
        }
      }
    } else {
      pair<string, int> nps(ps.first, -1);
      pair<int, int> npi(pi.first + T, pi.second + 1);
      auto iter = cost.find(nps);
      if (iter == cost.end() || iter->second > npi) {
        cost[nps] = npi;
        que.push(pair<pair<int, int>, pair<string, int> >(npi, nps));
      }
      for (const pair<string, int> &e : G[ps]) {
        pair<string, int> nps(e.first, ps.second);
        pair<int, int> npi(pi.first + e.second, pi.second);
        auto iter = cost.find(nps);
        if (iter == cost.end() || iter->second > npi) {
          cost[nps] = npi;
          que.push(pair<pair<int, int>, pair<string, int> >(npi, nps));
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
