#include #define clr(x) memset(x,0,sizeof(x)) #define clr_1(x) memset(x,-1,sizeof(x)) #define INF 0x3f3f3f3f #define LL long long #define pb push_back #define ls(i) (i<<1) #define rs(i) (i<<1|1) #define mp make_pair #define fi first #define se second #define mod 1000000007 using namespace std; const int N=1e3+100; struct edge{ int u,v,c; LL w; }e[N]; int n,m,k,T,tot,t; int u,v; LL w; char s[10]; bool tag[2][N]; int num[3]; LL ans[N]; LL minx[2]; int fa[N]; bool cmp(edge a,edge b) { return a.w>T; for(int kase=1;kase<=T;kase++) { cout<<"Case #"<>n>>m; tot=0; clr(num); for(int i=1;i<=m;i++) { cin>>u>>v>>w>>s; e[++tot]=(edge){u,v,(s[0]=='R'?0:(s[0]=='B'?1:2)),w}; num[e[i].c]++; } sort(e+1,e+m+1,cmp); clr(tag); for(int flag=0;flag<=1;flag++) { if(m-num[flag]1) minx[flag]=INF; } if(minx[0]==INF &&minx[1]==INF) { for(int i=1;i<=m;i++) cout<<"-1"<