unittest
{
	assert( [ "3", "6 5 1", "1 10 1" ].parse.expand.solve == "12\n11\n0" );
	assert( [ "4", "12 24 6", "52 16 4", "99 2 2" ].parse.expand.solve == "187\n167\n101\n0" );
	assert( [ "4", "12 13 1", "44 17 17", "66 4096 64" ].parse.expand.solve == "4162\n4162\n4162\n0" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto csfs = new long[ 3 ][ n - 1 ];
	foreach( ref csf; csfs )
	{
		input.popFront;
		csf = input.front.split.to!( long[] );
	}
	return tuple( n, csfs );
}

auto solve( long n, long[ 3 ][] csfs )
{
	long[] r;
	foreach( i; 0 .. n - 1 )
	{
		auto t = 0L;
		foreach( p, csf; csfs[ i .. $ ] )
		{
			// 待ち時間を加算
			if( t < csf[ 1 ] ) t = csf[ 1 ];
			else               t += t % csf[ 2 ];
			
			// 次の駅までかかる時間を加算
			t += csf[ 0 ];
		}
		r ~= t;
	}
	r ~= 0;
	
	return r.to!( string[] ).join( "\n" );
}
