#include<bits/stdc++.h>
using namespace std;
unsigned long long i, t, s, x, y, m, n;
char a[2000000000];
int main() {
std::ios::sync_with_stdio(false);
cin >> a >> t;
s = strlen(a);
for (i; i < t; i++) {
if ((i >= s) && (i + s - 1 < t)) {
x += m;
y += n;
i += s - 1;
continue;
} else if (i > s - 1) {
a[i] = a[i % s];
} else if (a[i] == 'N') {
y++;
} else if (a[i] == 'S') {
y--;
} else if (a[i] == 'W') {
x--;
} else if (a[i] == 'E') {
x++;
}
m = x;
n = y;
}
cout << x << " " << y;
return 0;
}