A drunk person was moving from one point on the street to another point on the same street. His starting point was between two manholes on that street. He was following a systematic scheme of his movement and had a fix movement repeated after an interval of time. How much time will he take to fall in the manhole and in which manhole will he fall in.

input 

The first line should contain number of test cases 'N' 
Next 'N' lines should have space separated inputs 'B' or 'F' which will depict the first movement of the drunk person in backward or forward direction respectively next five space separated numbers depict the distance of the hole in forward direction in meters distance of the hole in backward direction in meters forward steps in meters backward step in meters and time taken to complete 1 meter respectively

output 

In a single line print the manhole in which he will fall ‘F’ for the manhole that is in forward direction and ‘B’ for the manhole in backward direction followed by the time that he took to fall in that manhole and if he will not fall in any of the manhole then print 'SURVIVED'.

SAMPLE INPUT
4
F 10 10 4 3 1
B 10 10 3 4 2
F 15 10 3 5 4
F 19 12 3 3 2

SAMPLE OUTPUT
F46
B92
B160
SURVIVED
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n_test=int(raw_input(""))
debug=False
for test in range(n_test):
	inp=raw_input("").split(" ")
	d=inp[0]
	D="F"
	fw,bw,vf,vb,sp=map(int,inp[1:])
	spd_s=vf-vb
	spd_t=vf+vb
	t0=0
	if spd_s==0 and (d=="F" or vb<bw) and (d=="B" or vf<fw) :
		print "SURVIVED"
	elif (d=="B" and vb>bw):
		if debug: print "at first step"
		print "B%d" % (bw*sp)
	elif (d=="F" and vf>fw):
		if debug: print "at first step"
		print "F%d" % (fw*sp)
	else:		
		if spd_s<0:
			if debug: print "reverse"
			spd_s*= -1
			bw,fw=(fw,bw)
			vb,vf=(vf,vb)
			d="F" if d=="B" else "B"
			D="B"
		if d=="B":
			if debug: print "go forward"
			fw+=vb
			t0=vb*sp
		x1=vf
		t1=vf*sp
		r=fw-x1
		if r<0:
			t=t0+fw*sp
			ns=0
		else:
			ns=r/spd_s
			t=ns*spd_t*sp + t1 + t0
		if ns*spd_s<r: #need to add the partial forward step
			if debug: print "need partial forward step",r,fw-(ns*spd_s+x1-vb),(fw-(ns*spd_s+x1-vb))*sp,vb*sp
			t+=(fw-(ns*spd_s+x1-vb)+vb)*sp
		if debug: print "spd_s:%d spd_t:%d d:%s D:%s vf:%d vb:%d fw:%d" % (spd_s,spd_t,d,D,vf,vb,fw)
		if debug: print "t0:%d t1:%d x1:%d r:%d ns:%d" % (t0,t1,x1,r,ns)
		print "%s%d" %(D,t)