#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

void solve(){
	ll n = 1e9;
	string s;cin>>s;
	stack<char> st;
	vector<int>v;
	map<char, ll> mp;
	ll sum = 1;
	for(int i = 0; i < s.size(); ++i){
		if(s[i]>='2' && s[i] <= '9'){
			v.push_back(s[i] - '0');
			continue;
		}
		if(s[i]!=')'){
			st.push(s[i]);
			continue;
		}
		ll sum = 1;
		for(auto x : v){
			sum *= x;
			sum %= n;
		}
		v.pop_back();
		while(st.top()!='('){
			int ch = st.top();
			mp[ch] += sum;
			mp[ch] %= n;
			st.pop();
		}
		st.pop();
	}
	while(!st.empty()){
		int ch = st.top();
		mp[ch] += sum;
		mp[ch] %= n;
		st.pop();
	}
	ll X = 0, y = 0;
	for(auto x : mp){
		X%=n;
		y%=n;
		if(x.first=='N'){
			y -= x.second;
			y += n;
		} else if(x.first=='S'){
			y += x.second;
		} else if(x.first=='E'){
			X += x.second;
		} else{
			X -= x.second;
			X += n;
		}
		X%=n;
		y%=n;
	}
	X += n;y += n;
	X%=n;
	y%=n;
	cout<<X + 1<<" "<<y + 1<<endl;
	
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;cin>>t;
	for(int i = 0; i < t; ++i){
		cout<<"Case #"<<i+1<<": ";
		solve();
	}
	return 0;
}