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, st, gl;
string a, b;
map<string, int> id;
vector<int> rail[50000], cost[50000];
vector<pair<int, int> > pos[100000];
int est[100000];
inline int get(const string &s) {
  if (id.count(s)) return id[s];
  int n = id.size();
  return id[s] = n;
}
void precalc() {
  for (int i = 0; i < (int)n; i++) est[i] = inf;
  priority_queue<pair<int, int> > q;
  for (int i = 0; i < (int)pos[st].size(); i++) q.push(make_pair(0, gl));
  while (!q.empty()) {
    int cur = q.top().second, co = q.top().first;
    q.pop();
    if (est[cur] <= -co) continue;
    est[cur] = -co;
    for (int i = 0; i < (int)pos[cur].size(); i++)
      for (int d = 0; d < (int)2; d++) {
        pair<int, int> nxt = pos[cur][i];
        nxt.second += d ? 1 : -1;
        if (nxt.second < 0 || nxt.second >= rail[nxt.first].size() ||
            est[rail[nxt.first][nxt.second]] < inf)
          continue;
        q.push(make_pair(co - cost[nxt.first][nxt.second - d],
                         rail[nxt.first][nxt.second]));
      }
  }
}
bool calc() {
  set<pair<int, int> > s;
  priority_queue<pair<pair<int, int>, pair<pair<int, int>, pair<int, int> > > >
      q;
  for (int i = 0; i < (int)pos[st].size(); i++)
    q.push(make_pair(make_pair(-est[st], 0),
                     make_pair(make_pair(0, 0), pos[st][i])));
  while (!q.empty()) {
    pair<int, int> cur = q.top().second.second, co = q.top().second.first;
    int cid = rail[cur.first][cur.second];
    q.pop();
    if (s.count(cur)) continue;
    s.insert(cur);
    if (cid == gl) {
      cout << -co.first << " " << -co.second << endl;
      return 1;
    }
    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() ||
            s.count(nxt))
          continue;
        if (pos[cid][i] != cur) nco.first -= t, nco.second--;
        nco.first -= cost[nxt.first][nxt.second - d];
        pair<int, int> nest = nco;
        nco.first -= est[rail[nxt.first][nxt.second]];
        q.push(make_pair(nest, make_pair(nco, nxt)));
      }
  }
  return 0;
}
int main() {
  cin >> n >> t >> a >> b;
  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);
    }
  }
  precalc();
  if (est[st] < inf && !calc()) cout << -1 << endl;
  return 0;
}
