#include using namespace std; const int mmax=1e6+42,nmax=1e5+42,MX=1e7+42; struct edges { int u,v,c; }; edges inp[mmax]; bool cmp(edges a,edges b) { return a.c>b.c; } int X[MX],Y[MX],Z[MX]; int parent[nmax]; int root(int node) { if(node==parent[node])return node; parent[node]=root(parent[node]); return parent[node]; } int mini[20][nmax]; int depth[nmax]; int up[20][nmax]; vector< pair > adj[nmax]; stack< pair > dfs_stack; void dfs(int node,int par) { up[0][node]=par; for(int i=1;i<20;i++)up[i][node]=up[i-1][up[i-1][node]]; for(int j=1;j<20;j++) mini[j][node]=min(mini[j-1][node],mini[j-1][up[j-1][node]]); depth[node]=depth[par]+1; for(auto w:adj[node]) if(w.first!=par) { int other=w.first; mini[0][other]=w.second; dfs_stack.push({other,node}); } } void hand_dfs() { dfs_stack.push({1,1}); while(dfs_stack.size()) { pair cur=dfs_stack.top(); dfs_stack.pop(); dfs(cur.first,cur.second); } } int ask(int u,int v) { int ret=1e9; if(depth[u]depth[v] for(int i=19;i>=0;i--) if(depth[u]-(1<=depth[v]) { ret=min(ret,mini[i][u]); u=up[i][u]; } if(u==v)return ret; for(int i=19;i>=0;i--) if(up[i][u]!=up[i][v]) { ret=min(ret,mini[i][u]); u=up[i][u]; ret=min(ret,mini[i][v]); v=up[i][v]; } ret=min(ret,mini[0][u]); ret=min(ret,mini[0][v]); return ret; } int n,m; int main() { freopen("travelling.in","r",stdin); freopen("travelling.out","w",stdout); scanf("%i%i",&n,&m); for(int i=1;i<=m;i++)scanf("%i%i%i",&inp[i].u,&inp[i].v,&inp[i].c); int q,w; scanf("%i%i",&q,&w); for(int i=1;i<=3;i++) scanf("%i%i%i",&X[i],&Y[i],&Z[i]); for(int i=4;i<=q;i++) { X[i]=( ( X[i-3] + ( X[i-2] ^ X[i-1] ) ) % n ) +1; Y[i]=( ( Y[i-3] + ( Y[i-2] ^ Y[i-1] ) ) % n ) +1; Z[i]=( ( Z[i-3] + 1LL*( Z[i-2] ^ Z[i-1] ) ) % w ) +1; } sort(inp+1,inp+m+1,cmp); for(int i=1;i<=n;i++)parent[i]=i; for(int i=1;i<=m;i++) if(root(inp[i].u)!=root(inp[i].v)) { adj[inp[i].u].push_back({inp[i].v,inp[i].c}); adj[inp[i].v].push_back({inp[i].u,inp[i].c}); //cout<<"add "< "<