#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>


class Route;
struct Train {
	const Route* route;
	int position;
	Train(const Route* r, const int pos) : route{ r }, position{ pos }{};
	int station() const;
};
struct Passenger {
	Train train;
	int time, change;
	Passenger(const Train& t, const int ti, const int ch) : train{ t }, time{ ti }, change{ ch }{};
	bool operator<(const Passenger& that) const { return (time == that.time) ? change < that.change : time < that.time; }
	bool operator>(const Passenger& that) const { return (time == that.time) ? change > that.change : time > that.time; }
};
class Route {
	std::multimap<int, Train> map;
	std::vector<std::vector<std::pair<int, Train>>> cache;
public:
	std::vector<int> stations;
	std::vector<int> times;
	const int id;
	Route(const int i, std::vector<int>&& station, std::vector<int>&& time) : stations{ std::move(station) }, times{ std::move(time) }, id{ i } {
		cache.reserve(stations.size());
		for (auto i = 0; i < stations.size(); ++i) {
			map.emplace(stations[i], Train{ this, i });
			if (i == 0) {
				cache.push_back({ std::make_pair(times[i], Train{ this, i + 1 }) });
			}
			else if (i == stations.size() - 1) {
				cache.push_back({ std::make_pair(times[i - 1], Train{ this, i - 1 }) });
			}
			else {
				cache.push_back({ std::make_pair(times[i], Train{ this, i + 1 }), std::make_pair(times[i - 1], Train{ this, i - 1 }) });
			}
		}
	}
	const std::vector<std::pair<int, Train>>& next(const int position) const { return cache[position]; }
	const auto change(const int station) const { return map.equal_range(station); }
};
int Train::station() const
{
	return route->stations[position];
}
int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int n, change_time; std::cin >> n >> change_time;
	std::string from, to; std::cin >> from >> to;
	std::map<std::string, int> station_id; station_id.emplace(from, 0); station_id.emplace(to, 1);
	std::vector<Route> routes; routes.reserve(n); std::string name;
	for (auto i = 0; i < n; ++i) {
		int a; std::cin >> a;
		std::vector<int>stations(a); 
		for (auto& s : stations) {
			std::cin >> name;
			auto id = station_id.find(name);
			if (id != station_id.end()) {
				s = id->second;
			}
			else {
				s = station_id.size();
				station_id.emplace(name, station_id.size());
			}
		}
		std::vector<int>time(a - 1); for (auto& t : time) std::cin >> t;
		routes.emplace_back(i, std::move(stations), std::move(time));
	}
	std::vector<std::vector<Train>> change_train(station_id.size());
	for (const auto& route : routes) {
		for (auto pos = 0; pos < route.stations.size(); ++pos) {
			change_train[route.stations[pos]].emplace_back(&route, pos);
		}
	}
	std::vector<std::vector<int>> min_time(n); std::transform(routes.begin(), routes.end(), min_time.begin(), [](const Route& r) {return std::vector<int>(r.stations.size(), INT_MAX); });
	std::priority_queue<Passenger, std::vector<Passenger>, std::greater<Passenger>> queue;
	for (const auto& train : change_train[0]) {
		min_time[train.route->id][train.position] = 0;
		queue.emplace(train, 0, 0);
	}
	while (!queue.empty() && queue.top().train.station() != 1) {
		auto top = queue.top(); queue.pop();
		if (min_time[top.train.route->id][top.train.position] == top.time) {
			for (const auto& pair : top.train.route->next(top.train.position)) {
				if (min_time[pair.second.route->id][pair.second.position] > top.time + pair.first) {
					min_time[pair.second.route->id][pair.second.position] = top.time + pair.first;
					queue.emplace(pair.second, top.time + pair.first, top.change);
				}
			}
			for (const auto& next : change_train[top.train.station()]) {
				if (min_time[next.route->id][next.position] > top.time + change_time) {
					min_time[next.route->id][next.position] = top.time + change_time;
					queue.emplace(next, top.time + change_time, top.change + 1);
				}
			}
		}
	}
	if (queue.empty()) std::cout << -1 << std::endl;
	else std::cout << queue.top().time << " " << queue.top().change << std::endl;
}


Measured memory_bytes: 37684