#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

/* xxpoxx's definition */
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
using vl = vector<ll>;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

vector<ll> dijkstra(int s,int n,Graph g){
    typedef pair<ll,ll> P;
    vector<ll> d(n,LNF);
    priority_queue<P,vector<P>,greater<P>> que;
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;
        rep(i,0,g[v].size()){
            Edge e = g[v][i];
            if(d[e.to]>d[v]+e.weight){
                d[e.to] = d[v] + e.weight;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}

int main(){

    int n,m; cin >> n >> m;
    vector<vector<ll>> p(m,vector<ll>(3));
    rep(i,0,m){
        cin >> p[i][0] >> p[i][1] >> p[i][2];
        p[i][0]--;
        p[i][1]--;
    }
    int v0; cin >> v0;
    int a,b,c; cin >> a >> b >> c;
    Graph g(n*c);
    rep(i,0,m){
        int x = p[i][0];
        int y = p[i][1];
        ll t = p[i][2];
        rep(v,0,c){
            g[x*c+v].emplace_back(Edge(y*c+(a*v+b)%c,v*t));
            g[y*c+v].emplace_back(Edge(x*c+(a*v+b)%c,v*t));
        }
    }
    vector<ll> d = dijkstra(v0,n*c,g);
    ll ans = LNF;
    rep(i,0,c){
        vector<ll> e = dijkstra((n-1)*c+i,n*c,g);
        rep(j,0,c){
            chmin(ans,d[(n-1)*c+i]+e[j]);
        }
    }
    cout << ans << endl;
    /*
    ll N,S,P,C;
    cin >>N;
    vector<ll> r(N),score(N),Sr(N),Pr(N),Cr(N);
    for(ll i=0;i<N;i++) cin >>r[i];
    vector<pair<ll,ll>> s(N), p(N), c(N);
    for(ll i=0;i<N;i++){
        ll a1,a2,a3;
        cin >>a1>>a2>>a3;
        s[i]=make_pair(a1,i);
        p[i]=make_pair(a2,i);
        c[i]=make_pair(a3,i);
    }
    S=s[0].first; P=p[0].first; C=c[0].first;
    sort(s.begin(),s.end());
    sort(p.begin(),p.end());
    sort(c.begin(),c.end());
    reverse(s.begin(),s.end());
    reverse(p.begin(),p.end());
    reverse(c.begin(),c.end());
    //スマイルの初期点計算
    ll douritsu=0;
    ll rank=0;
    for(ll i=0;i<N;i++){
        score[s[i].second]+=r[rank];
        Sr[s[i].second]=rank;
        if(i!=N-1){
            if(s[i].first==s[i+1].first) douritsu++;
            else{
                rank+=douritsu+1;
                douritsu=0;
            }
        }
    }
    //ぴゅあの初期点計算
    douritsu=0;
    rank=0;
    for(ll i=0;i<N;i++){
        score[p[i].second]+=r[rank];
        Pr[p[i].second]=rank;
        if(i!=N-1){
            if(p[i].first==p[i+1].first) {
                douritsu++;
            }else{
                rank+=douritsu+1;
                douritsu=0;
            }
        }
    }
    //くーるの初期点計算
    douritsu=0;
    rank=0;
    for(ll i=0;i<N;i++){
        score[c[i].second]+=r[rank];
        Cr[c[i].second]=rank;
        if(i!=N-1){
            if(c[i].first==c[i+1].first) {
                douritsu++;
            }else{
                rank+=douritsu+1;
                douritsu=0;
            }
        }
    }
    vector<ll> score2 = score;
    ll ans=LNF;
    //for(ll j=1; j<N; j++) cout << score[j] << endl;
    // すまいるを値変えるとき
    for(ll i=S+1;i<=100;i++){
        for(ll j=0;j<N;j++){
            if(s[j].second==0) continue;
            if(s[j].first>i) continue;
            else if(s[j].first==i) score2[0]+=r[j]-r[Sr[0]];
            else if(s[j].first>=s[0].first) score2[j]+=r[Sr[j]]-r[Sr[j]+1];
        }
        ll rank=N;
        for(ll j=1; j<N; j++) {
            if(score2[j]<=score2[0]) rank--;
        }
        cout << i << " " << rank << endl;
        if(rank<=8) ans=min(ans,i-S);
    }
    cout << ans;
    */
}



Measured memory_bytes: 25720