#include <iostream>
#include <array>
#include <string>

using namespace std;

enum class Direction {
	North = 0,
	East,
	South,
	West,

	up = North,
	right,
	down,
	left,
};

struct NeighborData {
	int index;
    Direction direction;
};

class Dice{
public:
	Dice()
	: currentTopSurfaceIndex(0)
	, currentDirection(Direction::North) {}

	void input(){
	    inputNumber();
	    inputOrder();
	}

	void inputNumber(){
		for(auto&& e : number){
		    cin >> e;
	    }
	}

	void inputOrder(){
	    cin >> order;
	}

	void executeOrder(){
		while(1){
			char dir = fetchOrder();
			if(0 == dir) { return; }
			roll(dir);
		}
	}

	char fetchOrder(){
	    char c;
	    if(0 < order.length()) {
		    c = order.front();
	    	order.erase(order.begin());
	    }
		else{
		    c = 0;
	    }
	    return c;
	}


	void roll(char rollDirection){
		int backupTopSurfaceIndex = currentTopSurfaceIndex;
		Direction dir;
		switch(currentDirection) {
			case Direction::North:
				switch(rollDirection) {
					case 'N':
						dir = Direction::down;
						break;
					case 'E':
						dir = Direction::left;
						break;
					case 'S':
						dir = Direction::up;
						break;
					case 'W':
						dir = Direction::right;
						break;
					default:
						return;
				}
				break;
			case Direction::East:
				switch(rollDirection) {
					case 'N':
						dir = Direction::right;
						break;
					case 'E':
						dir = Direction::down;
						break;
					case 'S':
						dir = Direction::left;
						break;
					case 'W':
						dir = Direction::up;
						break;
					default:
						return;
				}
				break;
			case Direction::South:
				switch(rollDirection) {
					case 'N':
						dir = Direction::up;
						break;
					case 'E':
						dir = Direction::right;
						break;
					case 'S':
						dir = Direction::down;
						break;
					case 'W':
						dir = Direction::left;
						break;
					default:
						return;
				}
				break;
			case Direction::West:
				switch(rollDirection) {
					case 'N':
						dir = Direction::left;
						break;
					case 'E':
						dir = Direction::up;
						break;
					case 'S':
						dir = Direction::right;
						break;
					case 'W':
						dir = Direction::down;
						break;
					default:
						return;
				}
				break;
			        default:
						return;
				}

		currentTopSurfaceIndex = neighborTable[backupTopSurfaceIndex][(int)dir].index;
		currentDirection = (Direction)(((int)neighborTable[backupTopSurfaceIndex][(int)dir].direction + (int)currentDirection) % 4);
	}

	int getTopSurfaceNumber(){
		return number[currentTopSurfaceIndex];
	}

private:
	int number[6];
	int currentTopSurfaceIndex;
	Direction currentDirection;
	string order;
	// NeighborData neighbor[6][4]
	const NeighborData neighborTable[6][4] = {
	    /* up,      right,       down,      left     */
	    {{4, Direction::South}, {2, Direction::West},  {1, Direction::North}, {3, Direction::East}},
	    {{0, Direction::North}, {2, Direction::North}, {5, Direction::North}, {3, Direction::North}},
	    {{0, Direction::East},  {4, Direction::North}, {5, Direction::West},  {1, Direction::North}},
	    {{0, Direction::West},  {1, Direction::North}, {5, Direction::East},  {4, Direction::North}},
	    {{0, Direction::South}, {3, Direction::North}, {5, Direction::South}, {2, Direction::North}},
	    {{1, Direction::North}, {2, Direction::East},  {4, Direction::South}, {3, Direction::West}}};
};

int main(){
	Dice dice;
	dice.input();
	dice.executeOrder();
	cout << dice.getTopSurfaceNumber() << endl;
	return 0;
}


Measured memory_bytes: 3212