unittest
{
	assert( [ "2", "11 1 U", "11 47 D" ].solve == "230" );
	assert( [ "4", "20 30 U", "30 20 R", "20 10 D", "10 20 L" ].solve == "SAFE" );
	assert( [ "8", "168 224 U", "130 175 R", "111 198 D", "121 188 L", "201 116 U", "112 121 R", "145 239 D", "185 107 L" ].solve == "100" );
}



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto xyus = new Tuple!( long, long, dchar )[ n ];
	foreach( ref xyu; xyus )
	{
		input.popFront;
		auto as = input.front.split;
		xyu = tuple( as[ 0 ].to!( long ), as[ 1 ].to!( long ), as[ 2 ].to!( dchar ) );
	}
	
	// 衝突判定用基準値を作成
	long[][ long ] udss;
	long[][ long ] duss;
	long[][ long ] rlss;
	long[][ long ] lrss;
	long[][ long ] urss;
	long[][ long ] ulss;
	long[][ long ] drss;
	long[][ long ] dlss;
	long[][ long ] russ;
	long[][ long ] rdss;
	long[][ long ] ldss;
	long[][ long ] luss;
	foreach( i, xyu; xyus )
	{
		auto a = xyu[ 1 ] + xyu[ 0 ];
		auto b = xyu[ 1 ] - xyu[ 0 ];
		final switch( xyu[ 2 ] )
		{
			case 'U':
				udss[ xyu[ 0 ] ] ~= xyu[ 1 ];
				urss[ a ] ~= xyu[ 0 ];
				ulss[ b ] ~= xyu[ 0 ];
				break;
			
			case 'D':
				duss[ xyu[ 0 ] ] ~= xyu[ 1 ];
				drss[ b ] ~= xyu[ 0 ];
				dlss[ a ] ~= xyu[ 0 ];
				break;
			
			case 'R':
				rlss[ xyu[ 1 ] ] ~= xyu[ 0 ];
				russ[ a ] ~= xyu[ 0 ];
				rdss[ b ] ~= xyu[ 0 ];
				break;
			
			case 'L':
				lrss[ xyu[ 1 ] ] ~= xyu[ 0 ];
				luss[ b ] ~= xyu[ 0 ];
				ldss[ a ] ~= xyu[ 0 ];
				break;
		}
	}
	
	// 一番早い衝突の時間を計算
	auto a = solve2( udss, duss ) / 2;
	auto b = solve2( rlss, lrss ) / 2;
	auto c = solve2( russ, urss );
	auto d = solve2( ulss, luss );
	auto e = solve2( rdss, drss );
	auto f = solve2( dlss, ldss );
	auto ans = min( a, b, c, d, e, f );
	return ( ans == long.max / 2 ) ? "SAFE" : ans.to!( string );
}

auto solve2( long[][ long ] abss, long[][ long ] bass )
{
	auto t = long.max;
	foreach( k, ref abs; abss )
	{
		if( k !in bass ) continue;
		auto bas = bass[ k ];
		abs.sort;
		bas.sort;
		LOOP: for( auto i = 0L, j = 0L; i < abs.length; i++ )
		{
			while( bas[ j ] < abs[ i ] )
			{
				j++;
				if( bas.length <= j ) break LOOP;
			}
			auto tt = ( bas[ j ] - abs[ i ] ) * 10;
			t = min( t, tt );
		}
	}
	return t;
}
