data calc(int a,int b,int c,int n){ data ans; int s1=1ll*n*(n+1)%mod*inv2%mod,s2=1ll*n*(n+1)%mod*(n*2+1)%mod*inv6%mod; if(!a) { ans.f=1ll*(n+1)*(b/c)%mod; ans.g=1ll*s1*(b/c)%mod; ans.h=1ll*(b/c)*(b/c)%mod*(n+1)%mod; return ans; } if(a>=c||b>=c) { data res=calc(a%c,b%c,c,n); ans.f=(0ll+res.f+1ll*s1*(a/c)%mod+1ll*(n+1)*(b/c)%mod)%mod; ans.g=(0ll+res.g+1ll*s2*(a/c)%mod+1ll*s1*(b/c)%mod)%mod; ans.h=(0ll+res.h+1ll*(a/c)*res.g*2%mod+1ll*(b/c)*res.f*2%mod)%mod; ans.h=(0ll+ans.h+1ll*s2*(a/c)%mod*(a/c)%mod+1ll*n*(n+1)%mod*(b/c)%mod*(a/c)%mod)%mod; ans.h=(ans.h+1ll*(n+1)*(b/c)%mod*(b/c)%mod)%mod; return ans; }int m=(1ll*a*n+b)/c; data res=calc(c,c-b-1,a,m-1); ans.f=(1ll*m*n%mod-res.f+mod)%mod; ans.g=(1ll*m*n%mod*(n+1)%mod-res.h-res.f)%mod;ans.g=(1ll*ans.g*inv2%mod+mod)%mod; ans.h=(0ll+1ll*m*n%mod*(m+1)%mod-2ll*res.g-2ll*res.f-ans.f)%mod;ans.h=(ans.h+mod)%mod; return ans; }
intmain(){ int t;read(t); while(t--) { int a,b,c,n;read(n),read(a),read(b),read(c); data ans=calc(a,b,c,n); printf("%d %d %d\n",ans.f,ans.h,ans.g); } return0; }