Example

Input

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


Output

380 1
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,t;
vs in;
vi cost;
string Q[2];
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	int n;
	vvi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(){
		map<string,int>ma;
		rep(i,in.size())ma[in[i]]=1;
		int ww=0;
		for(auto &it:ma)it.second=ww++;
		vi used(ma.size());
		vvi tG(ma.size());
		rep(i,in.size())tG[ma[in[i]]].pb(i);
		
		d=vvi(n,vi(2,inf));
		priority_queue<tp>q;
		rep(i,in.size())if(in[i]==Q[0]){
			d[i][0]=d[i][1]=0;
			q.push(tp(0,0,i));
		}
		while(!q.empty()){
			int cost,co,pos;
			tie(cost,co,pos)=q.top();
			q.pop();
			cost*=-1;co*=-1;
			if(cost>d[pos][0])continue;
			if(cost==d[pos][0]&&co>d[pos][1])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int ncost=cost+e.cost;
				int nco=co;
				if(ncost<d[to][0]){
					d[to][0]=ncost;
					d[to][1]=nco;
					q.push(tp(-ncost,-nco,to));
				}else if(ncost==d[to][0]&&nco<d[to][1]){
					d[to][1]=nco;
					q.push(tp(-ncost,-nco,to));
				}
			}
			int w=ma[in[pos]];
			if(used[w]==0){
				used[w]=1;
				rep(i,tG[w].size()){
					int to=tG[w][i];
					int ncost=cost+t;
					int nco=co+1;
					if(ncost<d[to][0]){
						d[to][0]=ncost;
						d[to][1]=nco;
						q.push(tp(-ncost,-nco,to));
					}else if(ncost==d[to][0]&&nco<d[to][1]){
						d[to][1]=nco;
						q.push(tp(-ncost,-nco,to));
					}
				}
			}
		}
		int out1=inf,out2=inf;
		rep(i,in.size())if(in[i]==Q[1]){
			if(out1>d[i][0]){
				out1=d[i][0];
				out2=d[i][1];
			}else if(out1==d[i][0])
				out2=min(out2,d[i][1]);
		}
		if(out1==inf)cout<<-1<<endl;
		else cout<<out1<<" "<<out2<<endl;
	}
};
int main(){
	cin>>n>>t>>Q[0]>>Q[1];
	rep(i,n){
		int m;cin>>m;
		rep(j,m){
			string s;
			cin>>s;
			in.pb(s);
		}
		rep(j,m-1){
			int a;
			cin>>a;
			cost.pb(a);
		}
		cost.pb(inf);
	}
	DIJ dij(in.size());
	rep(i,cost.size()-1)dij.add_edge(i,i+1,cost[i]);
	dij.dij();
}











