UVa 10409 - Die Game

Summary
We have a dice (Die), and some commands (1-1024): north, south, east, west.

After performing the commands, what's the number in the top face of the Die?

Explanation
The initial position is: the numbers 1, 2, and 3 are seen on the top, north, and west faces, respectively.

2 3 1 4 5  6

Moves
From the initial position:

north generates: 1 3 5 4 6  2

south generates: 6 3 2 4 1  5

east generates: 2 6 3 1 5  4

west generates: 2 1 4 6 5  3

Input
1 north 3 north east south 10 north north south east south west north east north north 0

Output
5 1 6