#include "iostream"
#include "string.h"
#include "cstring"
#include "cstdlib"
#include "cstdio"
#define ll long long
using namespace std;
char s[50000005];
ll t;
struct node{
ll x,y;
}a[15];
int main(){
a[1].x=0;a[1].y=0;
cin>>s;
ll n=strlen(s);
scanf("%lld",&t);
for(ll i=0;i<t;i++){
s[i]=s[i%n];
if(s[i]=='E') a[1].x+=1;
if(s[i]=='S') a[1].y-=1;
if(s[i]=='W') a[1].x-=1;
if(s[i]=='N') a[1].y+=1;
}
printf("%lld %lld\n",a[1].x,a[1].y);
return 0;
}