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;
class State {
 public:
  int n, cost, sum;
  State(int n, int cost, int sum) : n(n), cost(cost), sum(sum) {}
  bool operator<(State second) const {
    if (cost != second.cost) return second.cost < cost;
    return second.sum < sum;
  }
};
vector<pair<int, int> > v[100010];
int n, t, c[100010];
string a, b, second[100010];
set<int> st;
vector<int> start, end;
pair<int, int> dis[100010];
priority_queue<State> pq;
map<int, vector<int> > M;
map<string, int> Ma;
int canp[100010];
pair<int, int> dijkstra() {
  for (int i = 0; i < 100010; i++) {
    dis[i].first = 1 << 28;
    dis[i].second = 1 << 28;
  }
  for (int i = 0; i < start.size(); i++) {
    pq.push(State(start[i], 0, 0));
    dis[start[i]] = make_pair(0, 0);
  }
  while (!pq.empty()) {
    State u = pq.top();
    pq.pop();
    if (st.find(u.n) != st.end()) return make_pair(u.cost, u.sum);
    if (dis[u.n] < make_pair(u.cost, u.sum)) continue;
    for (int i = 0; i < v[u.n].size(); i++) {
      int next = v[u.n][i].first, cost = dis[u.n].first + v[u.n][i].second,
          sum = dis[u.n].second;
      if (make_pair(cost, sum) < dis[next]) {
        dis[next] = make_pair(cost, sum);
        pq.push(State(next, cost, sum));
      }
    }
    vector<int> vi = M[canp[u.n]];
    for (int i = 0; i < vi.size(); i++) {
      if (vi[i] == u.n) continue;
      int next = vi[i], cost = dis[u.n].first + t, sum = dis[u.n].second + 1;
      if (make_pair(cost, sum) < dis[next]) {
        dis[next] = make_pair(cost, sum);
        pq.push(State(next, cost, sum));
      }
    }
  }
  return make_pair(-1, -1);
}
int main() {
  int k, count1 = 0, count2 = 0;
  cin >> n >> t;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) cin >> second[j];
    for (int j = 0; j < k - 1; j++) cin >> c[j];
    for (int j = 0; j < k; j++) {
      int con;
      if (Ma.find(second[j]) == Ma.end()) {
        count2++;
        con = count2;
        Ma[second[j]] = count2;
      } else
        con = Ma[second[j]];
      M[con].push_back(count1);
      canp[count1] = con;
      if (second[j] == a) start.push_back(count1);
      if (second[j] == b) st.insert(count1);
      if (i < k - 1) {
        v[count1].push_back(make_pair(count1 + 1, c[j]));
        v[count1 + 1].push_back(make_pair(count1, c[j]));
      }
      count1++;
    }
  }
  pair<int, int> p = dijkstra();
  if (p == make_pair(-1, -1))
    cout << -1 << endl;
  else
    cout << p.first << " " << p.second << endl;
  return 0;
}
