Example

Input

2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
3
Moscow Minsk Warsaw
100 150


Output

380 1
//=================================
// Created on: 2018/07/06 03:06:59
//=================================
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << (x) << endl
using namespace std;
constexpr int INF = 1 << 30;
struct CostGraph
{
    CostGraph(const int n) : V{n}, edge(n) {}
    struct Edge
    {
        Edge(const int from, const int to, const int cost) : from(from), to(to), cost(cost) {}
        const int from, to, cost;
    };
    void addEdge(const int from, const int to, const int cost) { edge[from].push_back(Edge{from, to, cost}), edge[to].push_back(Edge{to, from, cost}); }
    const int V;
    vector<vector<Edge>> edge;
};
vector<int> Dijkstra(const CostGraph& g, const int s)
{
    vector<int> d(g.V, INF);
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> q;
    d[s] = 0, q.push({0, s});
    while (not q.empty()) {
        const int cost = q.top().first, v = q.top().second;
        q.pop();
        if (d[v] < cost) { continue; }
        for (const auto& e : g.edge[v]) {
            if (d[e.to] <= d[v] + e.cost) { continue; }
            d[e.to] = d[v] + e.cost, q.push({d[e.to], e.to});
        }
    }
    return d;
}
int main()
{
    int N, T;
    string a, b;
    cin >> N >> T >> a >> b;
    map<string, int> mp;
    vector<vector<string>> s(N);
    vector<vector<int>> t(N);
    int sum = 0;
    for (int i = 0, a; i < N; i++) {
        cin >> a;
        for (int j = 0; j < a; j++) {
            string ss;
            cin >> ss;
            if (mp.find(ss) == mp.end()) {
                const int sz = mp.size();
                mp[ss] = sz;
            }
            s[i].push_back(ss), sum++;
        }
        for (int j = 0, tt; j < a - 1; j++) { cin >> tt, t[i].push_back(tt); }
    }
    vector<vector<int>> st(N);
    for (int i = 0; i < N; i++) {
        for (const string& n : s[i]) { st[i].push_back(mp[n]); }
    }
    CostGraph g(sum + mp.size());
    auto root = [&](const int s_) { return s_ + sum; };
    for (int i = 0, num = 0; i < N; i++) {
        for (int j = 0; j < st[i].size() - 1; j++) { g.addEdge(num, num + 1, 2 * t[i][j]), g.addEdge(root(st[i][j]), num, T), num++; }
        g.addEdge(root(st[i].back()), num, T), num++;
    }
    const int A = mp[a], B = mp[b];
    const auto d = Dijkstra(g, root(A));
    const int ans = d[root(B)] - 2 * T;
    if (ans == INF - 2 * T) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans / 2 << " ";
    auto dfs = [&](auto&& self, const int s) -> int {
        if (s == root(B)) { return 0; }
        int ans = INF;
        for (const auto& e : g.edge[s]) {
            if (d[e.to] == d[s] + e.cost) { ans = min(ans, (e.to >= sum ? 1 : 0) + self(self, e.to)); }
        }
        return ans;
    };
    cout << dfs(dfs, A) - 1 << endl;
    return 0;
}

