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;
int n, m, T;
set<pair<pair<int, int>, pair<int, int> > > G[100011];
vector<int> g[100011];
vector<bool> used[100011];
vector<pair<int, int> > D[100011];
priority_queue<pair<pair<int, int>, pair<int, int> >,
               vector<pair<pair<int, int>, pair<int, int> > >,
               greater<pair<pair<int, int>, pair<int, int> > > >
    Q;
pair<int, int> dijkstra(int a, int b) {
  while (!Q.empty()) {
    pair<pair<int, int>, pair<int, int> > t = Q.top();
    Q.pop();
    int cost = t.first.first, cnt = t.first.second;
    int y = t.second.first, x = t.second.second;
    int pos = g[y][x];
    if (D[y][x] < t.first) continue;
    used[y][x] = 1;
    if (pos == b) return t.first;
    for (set<pair<pair<int, int>, pair<int, int> > >::iterator i =
             G[pos].begin();
         i != G[pos].end(); i++) {
      pair<pair<int, int>, pair<int, int> > e = *i;
      int ncost = cost + e.first.second, ncnt = cnt;
      int ny = e.second.first, nx = e.second.second;
      if (used[ny][nx]) {
        G[pos].erase(i--);
        continue;
      }
      if (pos != a && (ny != y || abs(x - nx) != 1)) ncost += T, ncnt++;
      if (D[ny][nx] > pair<int, int>(ncost, ncnt)) {
        D[ny][nx] = pair<int, int>(ncost, ncnt);
        Q.push(pair<pair<int, int>, pair<int, int> >(D[ny][nx],
                                                     pair<int, int>(ny, nx)));
      }
    }
  }
  return pair<int, int>(-1, -1);
}
int main() {
  string second, t;
  cin >> m >> T >> second >> t;
  map<string, int> mp;
  mp[second] = n++;
  mp[t] = n++;
  for (int i = 0, a; i < m; i++) {
    cin >> a;
    D[i].resize(a, pair<int, int>((1e9), (1e9)));
    used[i].resize(a, 0);
    for (int j = 0; j < a; j++) {
      string str;
      cin >> str;
      if (!mp.count(str)) mp[str] = n++;
      if (str == second) D[i][j] = pair<int, int>(0, 0);
      if (str == second && Q.empty())
        Q.push(pair<pair<int, int>, pair<int, int> >(pair<int, int>(0, 0),
                                                     pair<int, int>(i, j)));
      g[i].push_back(mp[str]);
    }
    for (int j = 0, pre = g[i][0], cost; j < a - 1; j++) {
      cin >> cost;
      int pos = g[i][j + 1];
      G[pre].insert(pair<pair<int, int>, pair<int, int> >(
          pair<int, int>(pos, cost), pair<int, int>(i, j + 1)));
      G[pos].insert(pair<pair<int, int>, pair<int, int> >(
          pair<int, int>(pre, cost), pair<int, int>(i, j)));
      pre = pos;
    }
  }
  pair<int, int> ans = dijkstra(0, 1);
  if (ans == pair<int, int>(-1, -1))
    cout << -1 << endl;
  else
    cout << ans.first << " " << ans.second << endl;
  return 0;
}
