MOD = 1000000000

def f(a, update):
	for key in update:
		a = ''.join(update[key] if c == key else c for c in a)
	return eval(a) % MOD

t = int(raw_input())
for tc in range(t):
	print "Case #" + str(tc + 1) + ": ",

	a = raw_input()
	# prepend + and append * before every digit
	a = ''.join('+' + c + '*' if c.isdigit() else c for c in a)
	# add mod after every bracket to avoid large values
	a = ''.join(c + '%' + str(MOD) if c == ')' else c for c in a)
	# solve independently for both x and y co-ordinates
	y = f(a, {'S': '+1', 'N': '-1', 'E': '+0', 'W': '-0'})
	x = f(a, {'S': '+0', 'N': '-0', 'E': '+1', 'W': '-1'})
	print str(x + 1) + " " + str(y + 1)