#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX / 2
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T> &st){ os << "["; for(auto a : st) cout << a << ","; os << "]"; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N,M;
ll a,b,c;
ll v0;

using P = pair<ll,pair<ll,ll>>;
P makeP(ll a,ll b,ll c){
    return make_pair(a,make_pair(b,c));
}


struct edge{
    ll to,t;
    edge(){}
    edge(ll a,ll b): to(a),t(b){}
};
vector<edge> G[500];


vector<vector<ll>> dijkstra(ll s,ll t,ll sv){
    vector<vector<ll>> d(N,vector<ll>(c,LINF));
    d[s][sv] = 0;

    priority_queue<P,vector<P>,greater<P>> que;
    que.push(makeP(0,s,sv));
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        ll len = p.first;
        ll node = p.second.first;
        ll v = p.second.second;

//        cerr <<"pop : " << len << " " << node << " " << v << endl;

        if(d[node][v] < len) continue; 

        for(ll i=0;i<G[node].size();i++){
            edge e = G[node][i];
            ll nnode = e.to;
            ll t = e.t;
            ll nv = (a*v+b) % c;
            ll nlen = t * v + len;

            if(nlen < d[nnode][nv]){
                d[nnode][nv] = nlen;
                que.push(makeP(nlen,nnode,nv));
//                cerr << "push : " << nlen << " " << nnode << " " << nv << endl;
            }
        }
    }

    return d;
}

int main(){
    cin >> N >> M;
    rep(i,M){
        ll xx,yy,tt;
        cin >> xx >> yy >> tt;
        xx--;
        yy--;
        G[xx].push_back(edge(yy,tt));        
        G[yy].push_back(edge(xx,tt));
    }
    cin >> v0;
    cin >> a >> b >> c;


    vector<vector<ll>> d = dijkstra(0,N-1,v0);


    //for(ll i=0;i<N;i++){
    //    cout << d[i] << endl;
    //}

    ll ans = LINF;
    for(ll i=0;i<c;i++){
        // i is v0
        if(d[N-1][i]==LINF) continue;
        auto d2 = dijkstra(N-1,0,i);
        for(ll j=0;j<c;j++){
            if(d2[0][j]==LINF) continue;
            ans = min(ans,d[N-1][i]+d2[0][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8840