/*  -*- coding: utf-8 -*-
 *
 * 2819.cc: Country in Distortion
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_C = 50;
const long long LINF = 1LL << 61;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

struct Stat {
  ll d;
  int i, v;
  Stat() {}
  Stat(ll _d, int _i, int _v): d(_d), i(_i), v(_v) {}

  bool operator<(const Stat &s) const { return d > s.d; }
};

/* global variables */

vpii nbrs[MAX_N];
ll ds0[MAX_N][MAX_C], ds1[MAX_N][MAX_C];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int x, y, t;
    scanf("%d%d%d", &x, &y, &t);
    x--, y--;
    nbrs[x].push_back(pii(y, t));
    nbrs[y].push_back(pii(x, t));
  }

  int v0, a, b, c;
  scanf("%d%d%d%d", &v0, &a, &b, &c);

  for (int i = 0; i < n; i++) {
    fill(ds0[i], ds0[i] + c, LINF);
    fill(ds1[i], ds1[i] + c, LINF);
  }

  int gl = n - 1;
  ds0[0][v0] = 0;
  priority_queue<Stat> q;
  q.push(Stat(0, 0, v0));

  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (u.d != ds0[u.i][u.v]) continue;
    if (u.i == gl) continue;

    int vv = ((ll)a * u.v + b) % c;
    vpii &nbru = nbrs[u.i];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = u.d + (ll)u.v * vit->second;
      if (ds0[vi][vv] > vd) {
	ds0[vi][vv] = vd;
	q.push(Stat(vd, vi, vv));
      }
    }
  }
  //for (int j = 0; j < c; j++) printf("%lld ", ds0[gl][j]); putchar('\n');

  for (int j = 0; j < c; j++)
    if (ds0[gl][j] < LINF) {
      ds1[gl][j] = ds0[gl][j];
      q.push(Stat(ds0[gl][j], gl, j));
    }

  ll mind = LINF;
  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (u.d != ds1[u.i][u.v]) continue;
    if (u.i == 0) {
      mind = u.d;
      break;
    }

    int vv = ((ll)a * u.v + b) % c;
    vpii &nbru = nbrs[u.i];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = u.d + (ll)u.v * vit->second;
      if (ds1[vi][vv] > vd) {
	ds1[vi][vv] = vd;
	q.push(Stat(vd, vi, vv));
      }
    }
  }

  printf("%lld\n", mind);
  return 0;
}

