#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
//#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

class Dijkstra{
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    typedef std::pair<long long,int> P;
    std::vector<std::vector<P>> G;
    int V;
    std::priority_queue<P,std::vector<P>,std::greater<P>> que;
    
    public:
    void init(std::vector<std::pair<std::pair<int,int>,long long>> edge){
        //頂点数を決定する
        V=0;
        for(int i=0;i<edge.size();i++){
            V=std::max(V,edge[i].first.first+1);
            V=std::max(V,edge[i].first.second+1);
        }
        
        //辺集合を扱いやすい形式に変換する
        G.resize(V);
        for(int i=0;i<edge.size();i++){
            int from=edge[i].first.first,to=edge[i].first.second;
            long long cost=edge[i].second;
            G[from].push_back({cost,to});
        }
    }
    
    std::vector<long long> solve(int s){
        std::vector<long long> d;
        //INFで初期化する
        for(int i=0;i<V;i++){
            d.push_back(INF);
        }
        d[s]=0;
        que.push({0,s});
        //queは{cost,to}をコストが小さい順に出す
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(int i=0;i<G[v].size();i++){
                P e = G[v][i];
                if(d[e.second]>d[v]+e.first){
                    d[e.second] = d[v]+e.first;
                    que.push({d[e.second],e.second});
                }
            }
        }
        return d;
    }
    
    //init:{ {int,int},longlong}のvectorを渡すことで有向グラフを構築する
    //solve:始点を渡すとinitで構築したグラフでダイクストラをし、コストのvectorを返す
};


signed main(void){
    
    int N,M;
    long long x;
    vector<int> X,Y;
    vector<long long>T;
    int v0,A,B,C;
    
    cin >> N >> M;
    REP(i,M){
        cin >> x;x--;X.push_back(x);
        cin >> x;x--;Y.push_back(x);
        cin >> x;T.push_back(x);
    }
    cin >> v0 >> A >> B >> C;
    
    //行きの処理上の頂点番号 = 実際の頂点番号*50 + 速度
    //帰りの処理上の頂点番号 = (N+実際の頂点番号)*50 + 速度
    
    std::vector<std::pair<std::pair<int,int>,long long>> edge;
    std::pair<std::pair<int,int>,long long> h;
    
    //行き
    REP(i,M){
        REP(v,C){
            h.first.first = X[i]*50 + v;
            h.first.second = Y[i]*50 + (A*v+B)%C;
            h.second = T[i]*v;
            edge.push_back(h);
            
            h.first.first = Y[i]*50 + v;
            h.first.second = X[i]*50 + (A*v+B)%C;
            h.second = T[i]*v;
            edge.push_back(h);
        }
    }
    //帰り
    REP(i,M){
        REP(v,C){
            h.first.first = (N+X[i])*50 + v;
            h.first.second = (N+Y[i])*50 + (A*v+B)%C;
            h.second = T[i]*v;
            edge.push_back(h);
            
            h.first.first = (N+Y[i])*50 + v;
            h.first.second = (N+X[i])*50 + (A*v+B)%C;
            h.second = T[i]*v;
            edge.push_back(h);
        }
    }
    //行きのNと帰りのNを連結しておく
    REP(v,C){
        h.first.first = (N-1)*50 + v;
        h.first.second = (N+N-1)*50 + v;
        h.second = 0;
        edge.push_back(h);
    }
    
    Dijkstra dijkstra;
    dijkstra.init(edge);
    
    vector<long long> D = dijkstra.solve(0*50+v0);
    
    
    long long Ans=INF;
    REP(v,C){
        Ans = min(Ans,D[(N+0)*50+v]);
    }
    cout << Ans << endl;
    
    #if debug
    int s[9]={3,8,1,0,5,7,6,2,4};
    REP(i,C){
        REP(j,N){
            cout << D[(0+j)*50+s[i]] << " ";
        }cout << "   ";
        RREP(j,N){
            cout << D[(N+j)*50+s[i]] << " ";
        }cout << endl;
        
    }cout << endl;
    #endif
    
    return 0;
}





Measured memory_bytes: 54800