#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N,M; cin >> N >> M; vector A(N); vector> B(M); for(auto &[a,b,c,d,e,f] : B) cin >> a >> b >> c,a--,b--,c--,cin >> d >> e >> f; vector time(M); vector,vector>,greater<>>> Q(N); stack st; int idx = 0; for(auto &[x,y,z,v,l,r] : B){ if(v){ Q.at(x).push({(v+1)/2,idx,0}); Q.at(y).push({(v+1)/2,idx,0}); } else st.push(idx); idx++; } while(st.size()){ int pos = st.top(); st.pop(); auto &[x,y,z,v,l,r] = B.at(pos); if(A.at(z) >= l) continue; A.at(z) = l; int a = A.at(z); while(Q.at(z).size()){ auto [check,qpos,t] = Q.at(z).top(); if(check > a) break; Q.at(z).pop(); if(time.at(qpos) != t) continue; time.at(qpos)++; auto &[x2,y2,z2,v2,l2,r2] = B.at(qpos); if(A.at(x2)+A.at(y2) >= v2) st.push(qpos); else{ int add = (v2-A.at(x2)-A.at(y2)+1)/2; Q.at(x2).push({A.at(x2)+add,qpos,time.at(qpos)}); Q.at(y2).push({A.at(y2)+add,qpos,time.at(qpos)}); } } } bool ok = true; for(auto [x,y,z,v,l,r] : B){ if(A.at(x)+A.at(y) < v) continue; assert(A.at(z) >= l); if(A.at(z) > r){ok = false; break;} } if(ok){for(auto a : A) cout << a << " "; cout << "\n";} else cout << "-1\n"; } }