#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while (t--){
int n,num,x=0,y=0;
cin>>n;
char c;
while (n--){
cin>>c>>num;
if (c=='N')
y+=num;
if (c=='S')
y-=num;
if (c=='W')
x-=num;
if (c=='E')
x+=num;
}
cout<<abs(x)+abs(y)<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCl7CiAgICBpbnQgdDsKICAgIGNpbj4+dDsKICAgIHdoaWxlICh0LS0pewogICAgICAgIGludCBuLG51bSx4PTAseT0wOwogICAgICAgIGNpbj4+bjsKICAgICAgICBjaGFyIGM7CiAgICAgICAgd2hpbGUgKG4tLSl7CiAgICAgICAgICAgIGNpbj4+Yz4+bnVtOwogICAgICAgICAgICBpZiAoYz09J04nKQogICAgICAgICAgICAgICAgeSs9bnVtOwogICAgICAgICAgICBpZiAoYz09J1MnKQogICAgICAgICAgICAgICAgeS09bnVtOwogICAgICAgICAgICBpZiAoYz09J1cnKQogICAgICAgICAgICAgICAgeC09bnVtOwogICAgICAgICAgICBpZiAoYz09J0UnKQogICAgICAgICAgICAgICAgeCs9bnVtOwogICAgICAgIH0KICAgICAgICBjb3V0PDxhYnMoeCkrYWJzKHkpPDxlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0=