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 INF = (1 << 30);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
struct Edge {
  string to_name;
  int cost;
  int route_number;
  int order;
  Edge(string to_name_, int cost_, int route_number_, int order_) {
    to_name = to_name_;
    cost = cost_;
    route_number = route_number_;
    order = order_;
  }
};
struct Node {
  int cost;
  string station_name;
  int route_state;
  int cnt;
  int order;
  Node(int cost_, string station_name_, int route_state_, int cnt_,
       int order_) {
    cost = cost_;
    station_name = station_name_;
    route_state = route_state_;
    cnt = cnt_;
    order = order_;
  }
  bool operator<(const Node& node) const {
    if (cost == node.cost) {
      return (cnt < node.cnt);
    } else {
      return (cost < node.cost);
    }
  }
  bool operator>(const Node& node) const {
    if (cost == node.cost) {
      return (cnt > node.cnt);
    } else {
      return (cost > node.cost);
    }
  }
};
int N, T;
string A, B;
map<string, vector<Edge> > m;
pair<int, int> dijkstra(pair<int, int> s) {
  priority_queue<Node, vector<Node>, greater<Node> > q;
  map<pair<string, int>, int> used;
  q.push(Node(0, A, s.first, 0, s.second));
  while (!q.empty()) {
    Node p = q.top();
    q.pop();
    int now_cost = p.cost, now_route = p.route_state, now_cnt = p.cnt,
        now_order = p.order;
    string now_station = p.station_name;
    if (now_station == B) {
      return pair<int, int>(now_cost, now_cnt);
    }
    if (used[pair<string, int>(now_station, now_route)] == 1) continue;
    used[pair<string, int>(now_station, now_route)] = 1;
    vector<Edge> e = m[now_station];
    for (int i = 0; i < (e.size()); i++) {
      string next_station = e[i].to_name;
      int next_route = e[i].route_number, next_cost = e[i].cost,
          next_order = e[i].order;
      if (now_route == next_route &&
          (now_order == next_order + 1 || now_order == next_order - 1 ||
           now_order == next_order)) {
        q.push(Node(now_cost + next_cost, next_station, next_route, now_cnt,
                    next_order));
      } else {
        q.push(Node(now_cost + next_cost + T, next_station, next_route,
                    now_cnt + 1, next_order));
      }
    }
  }
  return pair<int, int>(-1, -1);
}
int main() {
  cin >> N >> T >> A >> B;
  for (int i = 0; i < (N); i++) {
    int a;
    vector<string> v;
    cin >> a;
    for (int j = 0; j < (a); j++) {
      string tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    for (int j = 0; j < (a - 1); j++) {
      int in_cost;
      cin >> in_cost;
      m[v[j]].push_back(Edge(v[j + 1], in_cost, i, j));
      m[v[j + 1]].push_back(Edge(v[j], in_cost, i, j + 1));
    }
  }
  vector<Edge> e = m[A];
  int min_cost = INF;
  int min_cnt = INF;
  bool flag = true;
  for (int i = 0; i < (e.size()); i++) {
    pair<int, int> result =
        dijkstra(pair<int, int>(e[i].route_number, e[i].order));
    if (min_cost > result.first) {
      min_cost = result.first;
      min_cnt = result.second;
    } else if (min_cost == result.first) {
      min_cnt = min(min_cnt, result.second);
    }
    if (result.first == -1 && result.second == -1) {
      flag = false;
      break;
    }
  }
  if (flag)
    cout << min_cost << " " << min_cnt << endl;
  else
    cout << "-1" << endl;
}
