unittest
{
	assert( [ "5", "1 2 1", "1 3 1", "2 4 1", "3 5 1", "3 1", "2 4", "2 3", "4 5" ].parse.expand.solve == "3\n2\n4" );
	assert( [ "7", "1 2 1", "1 3 3", "1 4 5", "1 5 7", "1 6 9", "1 7 11", "3 2", "1 3", "4 5", "6 7" ].parse.expand.solve == "5\n14\n22" );
	assert( [ "10", "1 2 1000000000", "2 3 1000000000", "3 4 1000000000", "4 5 1000000000", "5 6 1000000000", "6 7 1000000000", "7 8 1000000000", "8 9 1000000000", "9 10 1000000000", "1 1", "9 10" ].parse.expand.solve == "17000000000" );
}



import std.conv;
import std.range;
import std.stdio;
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.to!( long );
	auto abcs = new long[ 3 ][ n - 1 ];
	foreach( ref abc; abcs )
	{
		input.popFront;
		abc = input.front.split.to!( long[] );
	}
	input.popFront;
	auto qk = input.front.split.to!( long[] );
	auto xys = new long[ 2 ][ qk[ 0 ] ];
	foreach( ref xy; xys )
	{
		input.popFront;
		xy = input.front.split.to!( long[] );
	}
	return tuple( n, abcs, qk[ 1 ], xys );
}

auto solve( long n, long[ 3 ][] abcs, long k, long[ 2 ][] xys )
{
	auto ds = dijkstra( n + 1, abcs, k );
	auto anss = new long[ xys.length ];
	foreach( ref ans, xy; lockstep( anss, xys ) )
	{
		ans = ds[ xy[ 0 ] ] + ds[ xy[ 1 ] ];
	}
	return anss.to!( string[] ).join( "\n" );
}

auto dijkstra( bool directed = false )( long n, long[ 3 ][] es, long s )
{
	import std.container.binaryheap;
	
	auto tss = new Tuple!( long, long )[][ n ];
	foreach( e; es )
	{
		tss[ e[ 0 ] ] ~= tuple( e[ 1 ], e[ 2 ] );
		static if( !directed ) tss[ e[ 1 ] ] ~= tuple( e[ 0 ], e[ 2 ] );
	}
	
	auto ds = new long[ n ];
	auto dc = n;
	auto queue = heapify!( ( a, b ) => b[ 1 ] < a[ 1 ] )( [ tuple( s, 0L ) ] );
	ds[] = long.max;
	ds[ s ] = 0;
	while( !queue.empty )
	{
		auto fi = queue.front[ 0 ];
		auto fd = queue.front[ 1 ];
		queue.popFront();
		if( ds[ fi ] < fd ) continue;
		dc--;
		if( dc == 0 ) break;
		foreach( t; tss[ fi ] )
		{
			auto td = fd + t[ 1 ];
			if( ds[ t[ 0 ] ] < td ) continue;
			ds[ t[ 0 ] ] = td;
			queue.insert( tuple( t[ 0 ], td ) );
		}
	}
	return ds;
}
