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 = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int n, t;
string a, b;
map<string, int> id;
vector<int> rail[50000], cost[50000];
vector<pair<int, int> > pos[100000];
inline int get(const string &s) {
  if (id.count(s)) return id[s];
  int n = id.size();
  return id[s] = n;
}
int main() {
  cin >> n >> t >> a >> b;
  int st = get(a), gl = get(b);
  for (int i = 0; i < (int)n; i++) {
    int k, l;
    cin >> k;
    for (int j = 0; j < (int)k; j++) {
      string s;
      cin >> s;
      l = get(s);
      rail[i].push_back(l);
      pos[l].push_back(make_pair(i, j));
    }
    for (int j = 0; j < (int)k - 1; j++) {
      cin >> l;
      cost[i].push_back(l);
    }
  }
  set<pair<int, int> > in;
  map<pair<int, int>, pair<int, int> > dp;
  queue<pair<int, int> > q;
  for (int i = 0; i < (int)pos[st].size(); i++) {
    dp[pos[st][i]] = make_pair(0, 0);
    in.insert(pos[st][i]);
    q.push(pos[st][i]);
  }
  while (!q.empty()) {
    pair<int, int> cur = q.front(), co = dp[cur];
    int cid = rail[cur.first][cur.second];
    q.pop();
    in.erase(cur);
    if (cid == gl) {
      cout << -co.first << " " << -co.second << endl;
      return 0;
    }
    for (int i = 0; i < (int)pos[cid].size(); i++)
      for (int d = 0; d < (int)2; d++) {
        pair<int, int> nxt = pos[cid][i], nco = co;
        nxt.second += d ? 1 : -1;
        if (nxt.second < 0 || nxt.second >= rail[nxt.first].size()) continue;
        if (pos[cid][i] != cur) nco.first -= t, nco.second--;
        nco.first -= cost[nxt.first][nxt.second - d];
        if (dp.count(nxt) && dp[nxt] >= nco) continue;
        dp[nxt] = nco;
        if (!in.count(nxt)) in.insert(nxt), q.push(nxt);
      }
  }
  cout << -1 << endl;
  return 0;
}
