Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant.
A set of directions consists of several instructions. The first instruction is of the form "Begin on XXX", indicating the street that the route begins on. Each subsequent instruction is of the form "Left on XXX" or "Right on XXX", indicating a turn onto the specified road.
When reversing directions, all left turns become right turns and vice versa, and the order of roads and turns is reversed. See the sample input for examples.

-----Input-----
Input will begin with an integer T, the number of test cases that follow. Each test case begins with an integer N, the number of instructions in the route. N lines follow, each with exactly one instruction in the format described above.

-----Output-----
For each test case, print the directions of the reversed route, one instruction per line. Print a blank line after each test case.

-----Constraints-----
- 1 ≤ T ≤ 15
- 2 ≤ N ≤ 40
- Each line in the input will contain at most 50 characters, will contain only alphanumeric characters and spaces and will not contain consecutive spaces nor trailing spaces. By alphanumeric characters we mean digits and letters of the English alphabet (lowercase and uppercase).

-----Sample Input-----
2
4
Begin on Road A
Right on Road B
Right on Road C
Left on Road D
6
Begin on Old Madras Road
Left on Domlur Flyover
Left on 100 Feet Road
Right on Sarjapur Road
Right on Hosur Road
Right on Ganapathi Temple Road

-----Sample Output-----
Begin on Road D
Right on Road C
Left on Road B
Left on Road A

Begin on Ganapathi Temple Road
Left on Hosur Road
Left on Sarjapur Road
Left on 100 Feet Road
Right on Domlur Flyover
Right on Old Madras Road

-----Explanation-----
In the first test case, the destination lies on Road D, hence the reversed route begins on Road D. The final turn in the original route is turning left from Road C onto Road D. The reverse of this, turning right from Road D onto Road C, is the first turn in the reversed route.

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
T = int(input())
for i in range(0, T):
	l = []
	l2 = []
	n = int(input())
	for j in range(0, n):
		l.append(input())
	length = len(l)
	word = l[length - 1].split()
	direction = word[0]
	city = l[length - 1][l[length - 1].find('on') + 3:]
	temp = 'Begin on ' + city
	l2.append(temp)
	for i in range(2, length + 1):
		word = l[length - i].split()
		if direction == 'Right':
			direction = 'Left'
		else:
			direction = 'Right'
		city = l[length - i][l[length - i].find('on') + 3:]
		temp = direction + ' on ' + city
		l2.append(temp)
		direction = word[0]
	for sentence in l2:
		print(sentence)
	print('')


a = int(eval(input()))
for i in range(0, a):
	n = eval(input())
	k = n
	word = []
	for j in range(0, n):
		t = input()
		word.append(t)
		l = []
	flag = 0
	for j in range(k - 1, -1, -1):
		l = word[j].split()
		if j == k - 1:
			print('Begin', end=' ')
		elif right == 0:
			print('Right', end=' ')
		elif right == 1:
			print('Left', end=' ')
		if l[0] == 'Left':
			right = 0
		elif l[0] == 'Right':
			right = 1
		for index in range(1, len(l) - 1):
			print(l[index], end=' ')
		print(l[index + 1])
	print()


import sys

class Directions:
	ReversedDirections = []
	ReversedDirLines = []

	def __init__(self, dirLines, directions):
		self.DirLines = dirLines
		self.Directions = directions

def FormReversedDirLines(d):
	i = -1
	j = 0
	ReversedDirLines = []
	while i >= -1 * len(d.DirLines):
		direction = d.ReversedDirections[j]
		t = ' '.join(d.DirLines[i].split()[1:])
		ReversedDirLines.append(direction + ' ' + t)
		i = i - 1
		j = j + 1
	return ReversedDirLines

def CorrectDirections(directions):
	correctedDirs = [directions[0]]
	for d in directions[1:]:
		if d == 'Right':
			correctedDirs.append('Left')
		else:
			correctedDirs.append('Right')
	return correctedDirs

def Reverse(l):
	newL = []
	i = -1
	while i >= -1 * len(l):
		newL.append(l[i])
		i = i - 1
	return newL

def RightCircularShift(l):
	newL = l[1:]
	newL.append(l[0])
	return newL

def ReverseDirections(Directions):
	rShiftDirs = RightCircularShift(Directions)
	reverse = Reverse(rShiftDirs)
	reverse = CorrectDirections(reverse)
	return reverse

def WriteOutput(fPath, output):
	f = open(fPath, 'w')
	for d in output:
		f.writelines(d.ReversedDirLines)
		f.write('\n')
	f.close()

def WriteOutputToConsole(output):
	for d in output:
		for l in d.ReversedDirLines:
			print(l)
		print('')

def GetDirectionsFromLines(lines):
	directions = []
	for l in lines:
		directions.append(l.split()[0])
	return directions

def ReadInputFromConsole():
	lines = []
	k = input()
	while k != '':
		lines.append(k)
		k = input()
	return ParseInput(lines)

def ParseInput(lines):
	nCases = int(lines[0])
	parsedLines = []
	prev = 0
	i = 0
	while i < nCases:
		numLineIndex = prev + 1
		nDirLines = int(lines[numLineIndex])
		parsedLines.append(lines[numLineIndex + 1:numLineIndex + 1 + nDirLines])
		i = i + 1
		prev = prev + 1 + nDirLines
	inputDirs = []
	for p in parsedLines:
		dirLines = p
		directions = GetDirectionsFromLines(p)
		inputDirs.append(Directions(dirLines, directions))
	return inputDirs

def ReadInput(fPath):
	f = open(fPath, 'r')
	lines = f.readlines()
	f.close()
	return ParseInput(lines)

def __starting_point():
	directions = ParseInput(sys.stdin.readlines())
	for d in directions:
		d.ReversedDirections = ReverseDirections(d.Directions)
		d.ReversedDirLines = FormReversedDirLines(d)
	WriteOutputToConsole(directions)
__starting_point()


tc = int(input())
while tc:
	n = int(input())
	direction = []
	road = []
	for i in range(0, n):
		line = input()
		direction.append(line[0])
		if line[0] == 'B' or line[0] == 'R':
			road.append(line[9:])
		else:
			road.append(line[8:])
	print('Begin on ' + road[n - 1])
	for i in range(0, n - 1):
		if direction[n - i - 1] == 'R':
			op = 'Left on '
		else:
			op = 'Right on '
		print(op + road[n - i - 2])
	print()
	tc -= 1


t = eval(input())
for q in range(t):
	n = eval(input())
	a = []
	for i in range(n):
		a.append(input().split())
		s = ''
		for x in range(2, len(a[i])):
			s += ' ' + a[i][x]
		a[i][2] = s
	ans = 'Begin on' + a[n - 1][2] + '\n'
	i = n - 2
	while i > -1:
		if a[i + 1][0] == 'Left':
			ans += 'Right on'
		else:
			ans += 'Left on'
		ans += a[i][2] + '\n'
		i -= 1
	print(ans)


t = int(input())
listd = []
listr = []
while t:
	n = int(input())
	x = n
	while n:
		(a, b) = input().split(' on ')
		listd.append(a)
		listr.append(b)
		n = n - 1
	print('Begin on ' + listr.pop())
	listd.pop(0)
	x = x - 1
	while x:
		temp = listd.pop()
		if temp == 'Left':
			print('Right on ' + listr.pop())
		else:
			print('Left on ' + listr.pop())
		x = x - 1
	print('')
	t = t - 1


cases = int(input())
for case in range(cases):
	N = int(input())
	A = []
	B = []
	for n in range(N):
		(x, y) = input().split(' on ')
		A.append(x)
		B.append(y)
	x = n
	y = n - 1
	print(A[0], 'on', B[n])
	for y in range(N - 1, 0, -1):
		if A[x] == 'Right':
			print('Left on', B[y - 1])
		else:
			print('Right on', B[y - 1])
		x -= 1
	if case != cases - 1:
		print('')


T = int(input())
for _ in range(T):
	N = int(input())
	road = []
	for _ in range(N):
		t = input()
		if t[0] == 'B':
			road.append(('B', t[5:]))
		elif t[0] == 'R':
			road.append(('R', t[5:]))
		else:
			road.append(('L', t[4:]))
	for x in range(N):
		(Tprev, temp) = road.pop()
		if x == 0:
			print('Begin' + temp)
		elif prev == 'L':
			print('Right' + temp)
		else:
			print('Left' + temp)
		prev = Tprev
	print()


import sys
t = int(input())
while t > 0:
	n = int(input())
	ins = []
	while n > 0:
		s = input()
		ins.append(s)
		n -= 1
	idx = len(ins) - 2
	if ins[idx + 1].startswith('Left'):
		print('Begin' + ins[idx + 1][4:])
	else:
		print('Begin' + ins[idx + 1][5:])
	while idx >= 0:
		if ins[idx + 1].startswith('Left'):
			if ins[idx].startswith('Left'):
				print('Right' + ins[idx][4:])
			else:
				print('Right' + ins[idx][5:])
		elif ins[idx].startswith('Left'):
			print('Left' + ins[idx][4:])
		else:
			print('Left' + ins[idx][5:])
		idx -= 1
	print('')
	t -= 1


import sys
line = sys.stdin.readline()
t = int(line)
for i in range(0, t):
	line = sys.stdin.readline()
	n = int(line)
	r = []
	lr = []
	line = sys.stdin.readline()
	line = line.strip()
	r.append(line[9:])
	lr.append(-1)
	for j in range(1, n):
		line = sys.stdin.readline()
		line = line.strip()
		if line[0:7] == 'Left on':
			lr.append(0)
			r.append(line[8:])
		else:
			lr.append(1)
			r.append(line[9:])
	print('Begin on ' + r[n - 1])
	j = n - 1
	while j > 0:
		if lr[j]:
			print('Left on ' + r[j - 1])
		else:
			print('Right on ' + r[j - 1])
		j = j - 1
	print('')


def opp(a):
	if a == 'Right':
		return 'Left'
	else:
		return 'Right'

def main():
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		a = []
		for i in range(n):
			a.append(list((_ for _ in input().split(' on '))))
		a.reverse()
		print('Begin on', a[0][1])
		for i in range(1, n):
			print(opp(a[i - 1][0]), 'on', a[i][1])
		print('')
main()


import sys
t = int(sys.stdin.readline())
for test in range(t):
	n = int(sys.stdin.readline())
	lines = [sys.stdin.readline().strip() for i in range(n)]
	turns = [x.split()[0] for x in lines][1:][::-1]
	turns = ['Right' if t == 'Left' else 'Left' for t in turns]
	turns = ['Begin'] + turns
	lines = lines[::-1]
	for i in range(n):
		print(turns[i], ' '.join(lines[i].split()[1:]))
	print()


T = int(input())
for t in range(T):
	N = int(input())
	p = []
	q = []
	for n in range(N):
		x = input().split()
		if x[0] == 'Right':
			p.append('Left')
		elif x[0] == 'Left':
			p.append('Right')
		q.append(' '.join(x[2:]))
	p.append('Begin')
	for n in range(N):
		print(p[-1 - n], 'on', q[-1 - n])
	print()