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 MOD = 1000000007;
const int INF = MOD + 1;
const long double EPS = 1e-12;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
struct Edge {
  int from, to;
  pair<int, int> cost;
  bool operator<(const Edge &e) const { return cost < e.cost; }
  bool operator>(const Edge &e) const { return cost > e.cost; }
};
void add_edge(vector<vector<Edge>> &g, int from, int to, pair<int, int> cost) {
  g[from].push_back(Edge{from, to, cost});
}
void dijkstra(vector<vector<Edge>> &g, int s, vector<pair<int, int>> &d) {
  d.assign(g.size(), pair<int, int>(INF, INF));
  d[s] = pair<int, int>(0, 0);
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>,
                 greater<pair<pair<int, int>, int>>>
      que;
  que.push(pair<pair<int, int>, int>(pair<int, int>(0, 0), s));
  while (!que.empty()) {
    pair<int, int> dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    for (int i = (int)(0); i < (int)(g[v].size()); i++) {
      Edge e = g[v][i];
      pair<int, int> ecost = e.cost;
      ecost.first += d[v].first, ecost.second += d[v].second;
      if (d[e.to] > ecost) {
        d[e.to] = ecost;
        que.push(pair<pair<int, int>, int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  vector<vector<Edge>> g;
  int n, t;
  cin >> n >> t;
  string a, b;
  cin >> a >> b;
  map<string, vector<int>> mp;
  for (int i = (int)(0); i < (int)(n); i++) {
    int m;
    cin >> m;
    int t = g.size();
    g.resize(t + m);
    string s;
    for (int j = (int)(0); j < (int)(m); j++) {
      cin >> s;
      mp[s].push_back(t + j);
    }
    for (int j = (int)(0); j < (int)(m - 1); j++) {
      int c;
      cin >> c;
      add_edge(g, t + j, t + j + 1, pair<int, int>(c, 0));
      add_edge(g, t + j + 1, t + j, pair<int, int>(c, 0));
    }
  }
  for (auto tmp : mp) {
    vector<int> v = tmp.second;
    for (int i = (int)(0); i < (int)(v.size()); i++)
      for (int j = (int)(0); j < (int)(v.size()); j++) {
        if (i == j) continue;
        add_edge(g, v[i], v[j], pair<int, int>(t, 1));
      }
  }
  if (mp[a].size() == 0 || mp[b].size() == 0) {
    puts("-1");
    return 0;
  }
  vector<int> v = mp[a];
  for (int i = (int)(0); i < (int)(v.size()); i++)
    for (int j = (int)(0); j < (int)(v.size()); j++) {
      if (i == j) continue;
      add_edge(g, v[i], v[j], pair<int, int>(0, 0));
    }
  v = mp[b];
  for (int i = (int)(0); i < (int)(v.size()); i++)
    for (int j = (int)(0); j < (int)(v.size()); j++) {
      if (i == j) continue;
      add_edge(g, v[i], v[j], pair<int, int>(0, 0));
    }
  int src = mp[a][0], dst = mp[b][0];
  vector<pair<int, int>> d;
  dijkstra(g, src, d);
  if (d[dst].first == INF)
    puts("-1");
  else
    cout << d[dst].first << " " << d[dst].second << endl;
  return 0;
}
