#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll dist[2][50][500][50];

struct S {
	int rev, sv, pos, v;
	ll d;

	bool operator <(const S& x) const {
		return d > x.d;
	}
};

ll rec(S s) {
	return dist[s.rev][s.sv][s.pos][s.v];
}

void save(S s) {
	dist[s.rev][s.sv][s.pos][s.v] = s.d;
}

struct edge {
	int to;
	ll t;
};

vector<edge> G[500];

int n, m, a, b, c, v0;

void dijkstra(int rev, int spos, int sv) {
	S s = { rev, sv, spos, sv, 0 };
	save(s);
	priority_queue<S> q;
	q.push(s);
	while(q.size()) {
		s = q.top();
		q.pop();
		ll d = rec(s);
		if(d < s.d) continue;
		//cout << d << endl;
		for(auto e : G[s.pos]) {
			S ns = { rev, sv, e.to, (a * s.v + b) % c, d + e.t * s.v };
			if(rec(ns) > ns.d) {
				save(ns);
				q.push(ns);
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n >> m;

	for(int i = 0; i < m; i++) {
		int x, y;
		ll t;
		cin >> x >> y >> t;
		x--, y--;
		G[x].push_back({ y, t });
		G[y].push_back({ x, t });
	}
	cin >> v0 >> a >> b >> c;

	const ll INF = 1LL << 60;
	fill((ll*)begin(dist), (ll*)end(dist), INF);

	dijkstra(0, 0, v0);
	for(int sv = 0; sv < 50; sv++) {
		dijkstra(1, n - 1, sv);
	}

	ll ans = INF;
	for(int v1 = 0; v1 < 50; v1++) {
		for(int v2 = 0; v2 < 50; v2++) {
			S s1 = { 0, v0, n - 1,v1 };
			S s2 = { 1, v1, 0,v2 };
			ans = min(ans, rec(s1) + rec(s2));
		}
	}
	cout << ans << endl;
}