#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;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwojZGVmaW5lIGVuZGwgJ1xuJwoKdm9pZCBzb2x2ZSgpewoJbGwgbiA9IDFlOTsKCXN0cmluZyBzO2Npbj4+czsKCXN0YWNrPGNoYXI+IHN0OwoJdmVjdG9yPGludD52OwoJbWFwPGNoYXIsIGxsPiBtcDsKCWxsIHN1bSA9IDE7Cglmb3IoaW50IGkgPSAwOyBpIDwgcy5zaXplKCk7ICsraSl7CgkJaWYoc1tpXT49JzInICYmIHNbaV0gPD0gJzknKXsKCQkJdi5wdXNoX2JhY2soc1tpXSAtICcwJyk7CgkJCWNvbnRpbnVlOwoJCX0KCQlpZihzW2ldIT0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