cin >> n >> m; for (int i = 1; i <= m; ++i) cin >> e[i].fr >> e[i].to >> e[i].c; t[cnt = 1] = 0; for (int i = 1; i <= m; ++i) for (int j = i; j <= m; ++j) t[++cnt] = (e[i].c + e[j].c + 1) / 2; sort(t + 1, t + cnt + 1); cnt = unique(t + 1, t + cnt + 1) - t - 1; cin >> p >> k >> a >> b >> c; ll ans = 0; for (int i = 1, x; i <= k; ++i) { if (i <= p) cin >> x; else x = (1ll * x * a + b) % c; Q[i] = x; } sort(Q + 1, Q + k + 1); t[cnt + 1] = INF; for (int i = 1, j = 1; i <= cnt; ++i) { for (int k = 1; k <= m; ++k) e[k].w = abs(e[k].c - t[i]); sort(e + 1, e + m + 1); ll mst = 0, coef = 0; init_fa(n); for (int k = 1; k <= m; ++k) { int u = e[k].fr, v = e[k].to, w = e[k].w, c = e[k].c, fu, fv; if ((fu = find(u)) == (fv = find(v))) continue; fa[fu] = fv; mst += w; coef += c <= t[i] ? 1 : -1; } while (j <= k && Q[j] >= t[i] && Q[j] < t[i + 1]) ans ^= mst + coef * (Q[j++] - t[i]); } cout << ans << "\n"; return0; }