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>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (int i = 0; i < (v.size()); i++) {
    os << v[i] << (i == v.size() - 1 ? "" : " ");
  }
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) {
    is >> x;
  }
  return is;
}
const int INF = 1e9 + 5;
struct Edge {
  int to;
  int cost;
  int other;
  Edge(int to, int cost, int other) : to(to), cost(cost), other(other) {}
};
struct Node {
  int dis;
  int trans;
  bool used;
  Node() : dis(INF), trans(INF), used(false) {}
  Node(int d, int t, bool f) : dis(d), trans(t), used(f) {}
};
pair<int, int> dijkstra(vector<vector<Edge>> g, int s, int t, int n) {
  vector<Node> node(n);
  node[s] = Node{0, 0, true};
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>,
                 greater<tuple<int, int, int>>>
      q;
  q.emplace(0, 0, s);
  while (not q.empty()) {
    int dis, trans, pos;
    tie(dis, trans, pos) = q.top();
    q.pop();
    node[pos].used = true;
    for (auto e : g[pos]) {
      if (node[e.to].used == true) continue;
      if (node[e.to].dis > dis + e.cost) {
        node[e.to].dis = dis + e.cost;
        node[e.to].trans = trans + e.other;
        q.emplace(node[e.to].dis, node[e.to].trans, e.to);
      } else if (node[e.to].dis == dis + e.cost and
                 node[e.to].trans > trans + e.other) {
        node[e.to].dis = dis + e.cost;
        node[e.to].trans = trans + e.other;
        q.emplace(node[e.to].dis, node[e.to].trans, e.to);
      }
    }
  }
  return make_pair(node[t].dis, node[t].trans);
}
void addEdge(vector<vector<Edge>>& g, int a, int b, int c, int d) {
  g[a].emplace_back(b, c, d);
  g[b].emplace_back(a, c, d);
}
int main() {
  int n, t;
  string a, b;
  cin >> n >> t >> a >> b;
  vector<vector<int>> ti(n), v(n);
  map<string, int> toId;
  int verSize = 0;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    verSize += x;
    v[i] = vector<int>(x);
    for (int j = 0; j < (x); j++) {
      string s;
      cin >> s;
      if (not toId.count(s)) toId[s] = toId.size();
      v[i][j] = toId[s];
    }
    ti[i] = vector<int>(x - 1);
    cin >> ti[i];
  }
  int p = 0;
  vector<vector<Edge>> g(verSize + toId.size());
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (v[i].size() - 1); j++) {
      addEdge(g, p + j, p + j + 1, ti[i][j], 0);
    }
    for (int j = 0; j < (v[i].size()); j++) {
      addEdge(g, p + j, verSize + v[i][j], 0, 1);
    }
    p += v[i].size();
  }
  pair<int, int> ans =
      dijkstra(g, toId[a] + verSize, toId[b] + verSize, verSize + toId.size());
  if (ans.first == INF) {
    cout << -1 << endl;
  } else {
    ans.second = ans.second / 2 - 1;
    cout << ans.first + ans.second * t << ' ' << ans.second << endl;
  }
}
