#include #include #include #define ll long long #define re register #define rep(i,s,t) for(re int i=s;i<=t;++i) using namespace std; #define gi(x) read(x) #define gii(x,y) read(x),read(y) #define giii(x,y,z) read(x),read(y),read(z) #define ms(f,x) memset(f,x,sizeof f) #define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) namespace IO{ #define gc getchar() #define pc(x) putchar(x) templateinline void read(T &x){ x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;} while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return; } templateinline void write(T x=0){ T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48); while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return; } } using IO::read; using IO::write; const int N=5e5+11; struct edge{ int x,y,z; char col[6]; inline void in(){ giii(x,y,z); scanf("%s",col); } inline bool operator<(edge A)const{ return z