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)
TU9EID0gMTAwMDAwMDAwMAoKZGVmIGYoYSwgdXBkYXRlKToKCWZvciBrZXkgaW4gdXBkYXRlOgoJCWEgPSAnJy5qb2luKHVwZGF0ZVtrZXldIGlmIGMgPT0ga2V5IGVsc2UgYyBmb3IgYyBpbiBhKQoJcmV0dXJuIGV2YWwoYSkgJSBNT0QKCnQgPSBpbnQocmF3X2lucHV0KCkpCmZvciB0YyBpbiByYW5nZSh0KToKCXByaW50ICJDYXNlICMiICsgc3RyKHRjICsgMSkgKyAiOiAiLAoKCWEgPSByYXdfaW5wdXQoKQoJIyBwcmVwZW5kICsgYW5kIGFwcGVuZCAqIGJlZm9yZSBldmVyeSBkaWdpdAoJYSA9ICcnLmpvaW4oJysnICsgYyArICcqJyBpZiBjLmlzZGlnaXQoKSBlbHNlIGMgZm9yIGMgaW4gYSkKCSMgYWRkIG1vZCBhZnRlciBldmVyeSBicmFja2V0IHRvIGF2b2lkIGxhcmdlIHZhbHVlcwoJYSA9ICcnLmpvaW4oYyArICclJyArIHN0cihNT0QpIGlmIGMgPT0gJyknIGVsc2UgYyBmb3IgYyBpbiBhKQoJIyBzb2x2ZSBpbmRlcGVuZGVudGx5IGZvciBib3RoIHggYW5kIHkgY28tb3JkaW5hdGVzCgl5ID0gZihhLCB7J1MnOiAnKzEnLCAnTic6ICctMScsICdFJzogJyswJywgJ1cnOiAnLTAnfSkKCXggPSBmKGEsIHsnUyc6ICcrMCcsICdOJzogJy0wJywgJ0UnOiAnKzEnLCAnVyc6ICctMSd9KQoJcHJpbnQgc3RyKHggKyAxKSArICIgIiArIHN0cih5ICsgMSk=