#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
vector<pii> g[525];
int v0,a,b,c;

ll dist[525*50];
ll dist2[50][525*50];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int x,y,t;
    scanf("%d%d%d",&x,&y,&t);
    --x;--y;
    g[x].push_back(pii(y,t));
    g[y].push_back(pii(x,t));
  }
  scanf("%d%d%d%d",&v0,&a,&b,&c);
  priority_queue<pll> Q;
  REP(i,n*50)dist[i] = 1e18;
  dist[0*50 + v0] = 0;
  Q.push(pll(-0, 0*50+v0));
  while(!Q.empty()){
    pll P = Q.top(); Q.pop();
    int pos = P.second;
    if(-P.first != dist[pos])continue;
    int p = pos/50;
    int v = pos%50;
    int nv = (a*v+b)%c;
    for(pii P : g[p]){
      int to = P.first;
      int tt = P.second;
      ll ndist = dist[pos] + (ll)tt*v;
      if(ndist < dist[to*50 + nv]){
        dist[to*50+nv] = ndist;
        Q.push(pll(-ndist, to*50 + nv));
      }
    }
  }

  REP(v1,50){
    REP(i,n*50)dist2[v1][i] = 1e18;
    dist2[v1][(n-1)*50+v1] = 0;
    Q.push(pll(-0, (n-1)*50+v1));
    while(!Q.empty()){
      pll P = Q.top(); Q.pop();
      int pos = P.second;
      if(-P.first != dist2[v1][pos])continue;
      int p = pos/50;
      int v = pos%50;
      int nv = (a*v+b)%c;
      for(pii P : g[p]){
        int to = P.first;
        int tt = P.second;
        ll ndist = dist2[v1][pos] + (ll)tt*v;
        if(ndist < dist2[v1][to*50 + nv]){
          dist2[v1][to*50+nv] = ndist;
          Q.push(pll(-ndist, to*50 + nv));
        }
      }
    }
  }

  ll ans = 1e18;
  REP(i,c)REP(j,c){
    CHMIN(ans, dist[(n-1)*50+i] + dist2[i][0+j]);
  }
  cout<<ans<<endl;
  return 0;
}