Dice I: Write a program to simulate rolling a dice, constructed by a net with faces labeled 1 to 6. Given integers assigned to each face and a sequence of commands (E, N, S, W), output the integer on the top face after the simulation. Constraints: 0 ≤ integer assigned to a face ≤ 100, 0 ≤ length of the command ≤ 100.

Sample Input 1:
1 2 4 8 16 32
SE
Sample Output 1:
8

Sample Input 2:
1 2 4 8 16 32
EESWN
Sample Output 2:
32

Explanation: Given a dice with integers assigned to faces 1 to 6, rolling it in the specified sequence of directions yields the integer on the top face.

# Buggy version:
class Dice():
    def __init__(self,num):
        self.num = num

    def east(self):
        temp = num
        num[1-1] = temp[4-1]
        num[4-1] = temp[6-1]
        num[6-1] = temp[3-1]
        num[3-1] = temp[1-1]

    def north(self):
        temp = num
        num[1-1] = temp[2-1]
        num[2-1] = temp[6-1]
        num[6-1] = temp[5-1]
        num[5-1] = temp[1-1]

    def south(self):
        temp = num
        num[1-1] = temp[5-1]
        num[5-1] = temp[6-1]
        num[6-1] = temp[2-1]
        num[2-1] = temp[1-1]

    def west(self):
        temp = num
        num[1-1] = temp[3-1]
        num[3-1] = temp[6-1]
        num[6-1] = temp[4-1]
        num[4-1] = temp[1-1]

num = list(map(int,input().split()))
dice = Dice(num)
command = input()
for c in command:
    if   c == 'E': dice.east()
    elif c == 'N': dice.north()
    elif c == 'S': dice.south()
    elif c == 'W': dice.west()
print(dice.num[0])
        



# Fixed version:
class Dice:
    def __init__(self,num):
        self.num = num.copy()
        
    def east(self):
        temp = self.num.copy()
        self.num[1-1] = temp[4-1]
        self.num[4-1] = temp[6-1]
        self.num[6-1] = temp[3-1]
        self.num[3-1] = temp[1-1]

    def north(self):
        temp = self.num.copy()
        self.num[1-1] = temp[2-1]
        self.num[2-1] = temp[6-1]
        self.num[6-1] = temp[5-1]
        self.num[5-1] = temp[1-1]

    def south(self):
        temp = self.num.copy()
        self.num[1-1] = temp[5-1]
        self.num[5-1] = temp[6-1]
        self.num[6-1] = temp[2-1]
        self.num[2-1] = temp[1-1]

    def west(self):
        temp = self.num.copy()
        self.num[1-1] = temp[3-1]
        self.num[3-1] = temp[6-1]
        self.num[6-1] = temp[4-1]
        self.num[4-1] = temp[1-1]

num = list(map(int,input().split()))
dice = Dice(num)
command = input()
for c in command:
    if   c == 'E': dice.east()
    elif c == 'N': dice.north()
    elif c == 'S': dice.south()
    elif c == 'W': dice.west()
print(dice.num[0])

# Buggy version:
import copy


class Dice:
    def __init__(self, eyes):
        self._top = eyes[0]
        self._front = eyes[1]
        self._right = eyes[2]
        self._left = eyes[3]
        self._back = eyes[4]
        self._bottom = eyes[5]

    @property
    def eye(self):
        return self._top

    def roll(self, direction):
        old = copy.copy(self)
        if direction == 'N':
            self._top = old._front
            self._front = old._bottom
            self._back = old._top
            self._bottom = old._back
        elif direction == 'S':
            self._top = old._back
            self._front = old._top
            self._back = old._bottom
            self._bottom = old._front
        elif direction == 'W':
            self._top = old._right
            self._right = old._back
            self._left = old._top
            self._back = old._left
        elif direction == 'E':
            self._top = old._left
            self._right = old._top
            self._left = old._back
            self._back = old._right
        else:
            raise ValueError('NEWS箱推し')


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)



# Fixed version:
import copy


class Dice:
    def __init__(self, eyes):
        self._top = eyes[0]
        self._front = eyes[1]
        self._right = eyes[2]
        self._left = eyes[3]
        self._back = eyes[4]
        self._bottom = eyes[5]

    @property
    def eye(self):
        return self._top

    def roll(self, direction):
        old = copy.copy(self)
        if direction == 'N':
            self._top = old._front
            self._front = old._bottom
            self._back = old._top
            self._bottom = old._back
        elif direction == 'S':
            self._top = old._back
            self._front = old._top
            self._back = old._bottom
            self._bottom = old._front
        elif direction == 'W':
            self._top = old._right
            self._right = old._bottom
            self._left = old._top
            self._bottom = old._left
        elif direction == 'E':
            self._top = old._left
            self._right = old._top
            self._left = old._bottom
            self._bottom = old._right
        else:
            raise ValueError('NEWS箱推し')


eyes = input().split()
dice = Dice(eyes)

direction_text = input()
for d in direction_text:
    dice.roll(d)

print(dice.eye)

# Buggy version:
class Cube:
    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    u, s, e, w, n, d = map(int, input().split())
    O = input()

    cube = Cube(u, s, e, w, n, d)
    for i in range(len(O)):
        cube.rotate(O[i])
    print(cube.u)


if __name__ == '__main__':
    main(


# Fixed version:
class Cube:
    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    u, s, e, w, n, d = map(int, input().split())
    O = input()

    cube = Cube(u, s, e, w, n, d)
    for i in range(len(O)):
        cube.rotate(O[i])
    print(cube.u)


if __name__ == '__main__':
    main()

# Buggy version:

    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
    print(dice.getTop())

# Fixed version:
class Dice:
    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

# Buggy version:
# 1: top, 2: front, 3: right,
# 4: left, 5: back, 6: bottom

class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for i in len(directions):
        d.roll(directions[i])

    print(d.get_top())

# Fixed version:
# 1: top, 2: front, 3: right,
# 4: left, 5: back, 6: bottom

class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for i in range(len(directions)):
        d.roll(directions[i])

    print(d.get_top())

# Buggy version:
import sys
data=list(map(int,input().split()))
order=sys.stdin.readline()
char_list=list(order)
for i in char_list:
	print(i)
	if i=='N':
		k=data[0]
		m=data[4]
		data[0]=data[1]
		data[1]=data[5]
		data[4]=k
		data[5]=m
	elif i=='E':
		k=data[0]
		m=data[2]
		data[0]=data[3]
		data[2]=k
		data[3]=data[5]	
		data[5]=m
	elif i=='S':
		k=data[0]
		m=data[1]
		data[0]=data[4]
		data[1]=k
		data[4]=data[5]
		data[5]=m
	elif i=='W':
		k=data[0]
		m=data[3]
		data[0]=data[2]
		data[2]=data[5]
		data[3]=k
		data[5]=m
print(data[0])

# Fixed version:
import sys
data=list(map(int,input().split()))
order=sys.stdin.readline()
char_list=list(order)
for i in char_list:
	
	if i=='N':
		k=data[0]
		m=data[4]
		data[0]=data[1]
		data[1]=data[5]
		data[4]=k
		data[5]=m
	elif i=='E':
		k=data[0]
		m=data[2]
		data[0]=data[3]
		data[2]=k
		data[3]=data[5]	
		data[5]=m
	elif i=='S':
		k=data[0]
		m=data[1]
		data[0]=data[4]
		data[1]=k
		data[4]=data[5]
		data[5]=m
	elif i=='W':
		k=data[0]
		m=data[3]
		data[0]=data[2]
		data[2]=data[5]
		data[3]=k
		data[5]=m
print(data[0])

# Buggy version:
class Dice:
  def __init__(self):
    self.top = 1
    self.front = 2
    self.left = 3

  @property
  def bottom(self):
    return 7 - self.top

  @property
  def back(self):
    return 7 - self.front

  @property
  def right(self):
    return 7 - self.left

  def move(self, direction):
    if direction == 'N':
      bottom = self.bottom
      self.top = self.front
      self.front = bottom
    elif direction == 'W':
      right = self.right
      self.left = self.top
      self.top = right
    elif direction == 'E':
      bottom = self.bottom
      self.top = self.left
      self.left = bottom
    elif direction == 'S':
      back = self.back
      self.front = self.top
      self.top = back


dice = Dice()
numbers = input().split()
for cmd in input():
  dice.move(cmd)
print(numbers[dice.top - 1])

# Fixed version:
class Dice:
  def __init__(self):
    self.top = 1
    self.front = 2
    self.left = 4

  @property
  def bottom(self):
    return 7 - self.top

  @property
  def back(self):
    return 7 - self.front

  @property
  def right(self):
    return 7 - self.left

  def move(self, direction):
    if direction == 'N':
      bottom = self.bottom
      self.top = self.front
      self.front = bottom
    elif direction == 'W':
      right = self.right
      self.left = self.top
      self.top = right
    elif direction == 'E':
      bottom = self.bottom
      self.top = self.left
      self.left = bottom
    elif direction == 'S':
      back = self.back
      self.front = self.top
      self.top = back

  def __repr__(self):
    print(self.__dict__)

dice = Dice()
numbers = input().split()
for cmd in input():
  dice.move(cmd)
print(numbers[dice.top - 1])

# Buggy version:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ???????????????????????°
		# ????????¶???
		self.x = [2, 5]
		self.y = [3, 4]
		self.z = [1, 6]
		SN = {'S': 0, 'N': 1}
		WE = {'W': 0, 'E': 1}
		pass

	def rotate(self, _dir):
		def rot(_k, _r):
			return list(reversed(_r)), _k

		if _dir=='N':
			self.x, self.z = rot(self.x, self.z)
		elif _dir=='S':
			self.z, self.x = rot(self.z, self.x)
		elif _dir=='E':
			self.z, self.y = rot(self.z, self.y)
		elif _dir=='W':
			self.y, self.z = rot(self.y, self.z)
		else:
			pass

	def top(self):
		return self.z[0]

	def view(self):
		print("x, y, z =", self.x, self.y, self.z)

if __name__=="__main__":
	val = list(map(int, input().split()))
	dice = Dice()
	dr = input()
	for d in dr:
		dice.rotate(d)
	print(val(dice.top()))

# Fixed version:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ???????????????????????°
		# ????????¶???
		self.x = [2, 5]
		self.y = [3, 4]
		self.z = [1, 6]
		SN = {'S': 0, 'N': 1}
		WE = {'W': 0, 'E': 1}
		pass

	def rotate(self, _dir):
		def rot(_k, _r):
			return list(reversed(_r)), _k

		if _dir=='N':
			self.x, self.z = rot(self.x, self.z)
		elif _dir=='S':
			self.z, self.x = rot(self.z, self.x)
		elif _dir=='E':
			self.z, self.y = rot(self.z, self.y)
		elif _dir=='W':
			self.y, self.z = rot(self.y, self.z)
		else:
			pass

	def top(self):
		return self.z[0]


if __name__=="__main__":
	dice = Dice()
	val = list(map(int, input().split()))
	dr = input()
	for d in dr:
		dice.rotate(d)
	print(val[dice.top()-1])

# Buggy version:
class Dice(object):
    def __init__(self):
        self.upside = 1
        self.frontside = 2
        self.rightside = 3
        self.backside = 4
        self.leftside = 5
        self.downside = 6
		
    def throwDice(self,dir):
        up = self.upside
        front = self.frontside
        left = self.leftside
        if dir == "S":
            self.frontside = up
            self.backside = 7-up
            self.downside = front
            self.upside = 7-front
			
        elif dir == "N":
            self.frontside = 7-up
            self.backside = up
            self.downside = 7-front
            self.upside = front
 		
        elif dir == "E":
            self.rightside = up
            self.leftside = 7-up
            self.upside = left
            self.downside = 7-left
		
        elif dir == "W":
            self.rightside = 7-up
            self.leftside = up
            self.upside = 7-left
            self.downside = left
	
    def getUpside(self):
        return self.upside
		
n = list(map(int,input().split()))
com = list(input())

dice = Dice()
for i in range(len(com)):
    dice.throwDice(com[i])

print(n[dice.getUpside()-1])

	
	
	

# Fixed version:
class Dice(object):
    def __init__(self):
        self.upside = 1
        self.frontside = 2
        self.rightside = 3
        self.backside = 5
        self.leftside = 4
        self.downside = 6
		
    def throwDice(self,dir):
        up = self.upside
        front = self.frontside
        left = self.leftside
        if dir == "S":
            self.frontside = up
            self.backside = 7-up
            self.downside = front
            self.upside = 7-front
			
        elif dir == "N":
            self.frontside = 7-up
            self.backside = up
            self.downside = 7-front
            self.upside = front
 		
        elif dir == "E":
            self.rightside = up
            self.leftside = 7-up
            self.upside = left
            self.downside = 7-left
		
        elif dir == "W":
            self.rightside = 7-up
            self.leftside = up
            self.upside = 7-left
            self.downside = left
	
    def getUpside(self):
        return self.upside
		
n = list(map(int,input().split()))
com = list(input())

dice = Dice()
for i in range(len(com)):
    dice.throwDice(com[i])

print(n[dice.getUpside()-1])

# Buggy version:
d=list(map(int,input().split()))
c=list(input())

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d)	
for com in c:
	roll(com)
print(dice1.d[0])

# Fixed version:
d=list(map(int,input().split()))
c=list(input())

class dice(object):
	def __init__(self, d):
		self.d = d

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d)	
for com in c:
	dice1.roll(com)
print(dice1.d[0])

# Buggy version:
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]

        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    @classmethod
    def Dice_create(cls,num):
            return cls(num)


num=list(map(int,input().split()))
command=input()
dice=Dice(num)
for i in range(len(command)):
    temp=dice.create(command[i])
    dice=Dice.Dice_create(temp)
    print(dice.f,dice.n,dice.e,dice.s,dice.w,dice.b)

# Fixed version:
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]

        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    @classmethod
    def Dice_create(cls,num):
            return cls(num)


num=list(map(int,input().split()))
command=input()
dice=Dice(num)
for i in range(len(command)):
    temp=dice.create(command[i])
    dice=Dice.Dice_create(temp)
print(dice.f)

# Buggy version:
d = [_ for _ in input().split()]                 
                                                 
commands = input()                               
                                                 
for c in commands:                               
  if c == 'E':                                   
    d[0], d[1], d[3], d[5] = d[1], d[5], d[0], d[
3]                                               
  elif c == 'W':                                 
    d[0], d[1], d[3], d[5] = d[3], d[0], d[5], d[
1]                                               
  elif c == 'N':                                 
    d[0], d[2], d[4], d[5] = d[2], d[5], d[0], d[
4]                                               
  elif c == 'S':                                 
    d[0], d[2], d[4], d[5] = d[4], d[0], d[5], d[
2]                                               
                                                 
print(d[0])                                      

# Fixed version:
d = [_ for _ in input().split()]

commands = input()

for c in commands:
  if c == 'E':
    d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
  elif c == 'W':
    d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
  elif c == 'N':
    d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
  elif c == 'S':
    d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]

print(d[0])

# Buggy version:
class Dice:

u,s,e,w,n,b = map(int,input().split())
roll = input()
for i in roll:
	if i == E:
		tmp = e
		e = u
		u = w
		w = b
		b = tmp
	elif i == S:
		tmp = s
		s = u
		u = n
		n = b
		b = tmp
	elif i == W:
		tmp = w
		w = u
		u = e
		e = b
		b = tmp
	elif i == N:
		tmp = n
		n = u
		u = s
		s = b
		b = tmp

print(u)

# Fixed version:
class Dice:
    u, s, e, w, n, b = map(int, input().split())
    roll = input()
    for i in roll:
        if i == "E":
            e,u,w,b = u,w,b,e
        elif i == "S":
            s,u,n,b = u,n,b,s
        elif i == "W":
            w,u,e,b = u,e,b,w
        elif i == "N":
            n,u,s,b = u,s,b,n
    print(u)

dice = Dice()

# Buggy version:
number = [int(x) for x in input().split()]
#S
#1 -> 2
#2 -> 6
#3 -> 3
#4 -> 4
#5 -> 1
#6 -> 5
order = input()

for i in range(len(order)):
    number_2 = number
    if order[i] == 'S':
        number[0] = number_2[4]
        number[1] = number_2[0]
        number[4] = number_2[5]
        number[5] = number_2[1]
    if order[i] == 'W':
        number[0] = number_2[2]
        number[2] = number_2[5]
        number[3] = number_2[0]
        number[5] = number_2[3]
    if order[i] == 'E':
        number[0] = number_2[3]
        number[2] = number_2[0]
        number[3] = number_2[5]
        number[5] = number_2[2]
    if order[i] == 'N':
        number[0] = number_2[1]
        number[1] = number_2[5]
        number[4] = number_2[0]
        number[5] = number_2[4]

print(number[0])

# Fixed version:
number = [int(x) for x in input().split()]
#S
#1 -> 2
#2 -> 6
#3 -> 3
#4 -> 4
#5 -> 1
#6 -> 5
order = input()

for i in range(len(order)):
    number_2 = [number[i] for i in range(len(number))]
    if order[i] == 'S':
        number[0] = number_2[4]
        number[1] = number_2[0]
        number[4] = number_2[5]
        number[5] = number_2[1]
    if order[i] == 'W':
        number[0] = number_2[2]
        number[2] = number_2[5]
        number[3] = number_2[0]
        number[5] = number_2[3]
    if order[i] == 'E':
        number[0] = number_2[3]
        number[2] = number_2[0]
        number[3] = number_2[5]
        number[5] = number_2[2]
    if order[i] == 'N':
        number[0] = number_2[1]
        number[1] = number_2[5]
        number[4] = number_2[0]
        number[5] = number_2[4]
    #print(number)

print(number[0])

# Buggy version:
dice = [1,2,3,4,5,6]
number = list(map(int,input().split()))
direction = str(input())

rotate_n =[2,6,4,3,1,5]
rotate_s =[5,1,3,4,6,2]
rotate_e =[4,2,1,6,5,3]
rotate_w =[3,2,6,1,5,4]

for i in direction:
    result = []
    if i == "N":
        for j in range(6):
            dice[j] = rotate_n[j]
    elif i == "S":
        for j in range(6):
            dice[j] = rotate_s[j]
    elif i == "E":
        for j in range(6):
            dice[j] = rotate_e[j]
    else:
        for j in range(6):
            dice[j] = rotate_w[j]
    for k in dice:
        result.append(number[k-1])
    number = result

print(number[1])

# Fixed version:
dice = [1,2,3,4,5,6]
number = list(map(int,input().split()))
direction = str(input())

rotate_n =[2,6,3,4,1,5]
rotate_s =[5,1,3,4,6,2]
rotate_e =[4,2,1,6,5,3]
rotate_w =[3,2,6,1,5,4]

for i in direction:
    result = []
    if i == "N":
        for j in range(6):
            dice[j] = rotate_n[j]
    elif i == "S":
        for j in range(6):
            dice[j] = rotate_s[j]
    elif i == "E":
        for j in range(6):
            dice[j] = rotate_e[j]
    else:
        for j in range(6):
            dice[j] = rotate_w[j]
    for k in dice:
        result.append(number[k-1])
    number = result

print(number[0])

# Buggy version:
#dice
D=[int(i) for i in input().split()]
Os=input()
for i in range(len(Os)):
    if Os[i]=="N":
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif Os[i]=="S":
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
elif Os[i]=="E":
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
elif Os[i]=="W":
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t        
print(D[0])

# Fixed version:
#dice
D=[int(i) for i in input().split()]
Os=input()
for i in range(len(Os)):
    if Os[i]=="N":
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif Os[i]=="S":
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif Os[i]=="E":
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif Os[i]=="W":
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t        
print(D[0])

# Buggy version:
class Dice:
    def __init__(self):
        self.dice=[1,2,3,4,5,6] # up,front,right,left,back,front
    def set(self,l):
        self.dice=l
    def roll(self, s):
        import copy
        mat=((1,4,3,2),(5,0,1,1),(2,2,0,5),(3,3,5,0),(0,5,4,4),(4,1,2,3))
        l=copy.deepcopy(self.dice)
        if s == 'N': c = 0
        if s == 'S': c = 1
        if s == 'E': c = 2
        if s == 'W': c = 3
        for i in range(6):
            print('i=%d, c=%d, mat[i][c]=%d, %d->%d'%(i,c,mat[i][c],self.dice[i],l[mat[i][c]]))
            self.dice[i]=l[mat[i][c]]
    def get(self):
        return self.dice

d=Dice()
d.set(list(map(int,input().split)))
s=input()
for i in range(len(s)):
    d.roll(s[i])
print(d.get()[0])

# Fixed version:
class Dice:
    def __init__(self):
        self.dice=[1,2,3,4,5,6] # up,front,right,left,back,front
    def set(self,l):
        self.dice=l
    def roll(self, s):
        import copy
        mat=((1,4,3,2),(5,0,1,1),(2,2,0,5),(3,3,5,0),(0,5,4,4),(4,1,2,3))
        l=copy.deepcopy(self.dice)
        if s == 'N': c = 0
        if s == 'S': c = 1
        if s == 'E': c = 2
        if s == 'W': c = 3
        for i in range(6):
            self.dice[i]=l[mat[i][c]]
    def get(self):
        return self.dice

d=Dice()
d.set(list(map(int,input().split())))
s=input()
for i in range(len(s)):
    d.roll(s[i])
print(d.get()[0])

# Buggy version:
class dice:
    directions = ['S', 'E', 'N', 'W']
    def __init__(self, strlabels):
        label = strlabels.split()
        self.top = label[0]
        self.side = label[1:5]
        self.side[2], self.side[3] = self.side[3], self.side[2]
        self.down = label[5]
        print(self.top, self.side, self.down)

    def roll(self, direction):
        tmp = self.top
        self.top = self.side[(self.directions.index(direction)+2)%4]
        self.side[(self.directions.index(direction)+2)%4] = self.down
        self.down = self.side[self.directions.index(direction)]
        self.side[self.directions.index(direction)] = tmp
        print(self.top, self.side, self.down)

    def pFace(self, initial):
        if initial == 'u':
            print(self.top)
        elif initial == 'd':
            print(self.down)
        else:
            print(self.side[directions.index(direction)])

dice1 = dice(input())
for direction in input():
    dice1.roll(direction)

dice1.pFace('u')

# Fixed version:
class dice:
    directions = ['S', 'E', 'N', 'W']
    def __init__(self, strlabels):
        label = strlabels.split()
        self.top = label[0]
        self.side = label[1:5]
        self.side[2], self.side[3] = self.side[3], self.side[2]
        self.down = label[5]
        #print(self.top, self.side, self.down)

    def roll(self, direction):
        tmp = self.top
        self.top = self.side[(self.directions.index(direction)+2)%4]
        self.side[(self.directions.index(direction)+2)%4] = self.down
        self.down = self.side[self.directions.index(direction)]
        self.side[self.directions.index(direction)] = tmp
        #print(self.top, self.side, self.down)

    def pFace(self, initial):
        if initial == 'u':
            print(self.top)
        elif initial == 'd':
            print(self.down)
        else:
            print(self.side[directions.index(direction)])

dice1 = dice(input())
for direction in input():
    dice1.roll(direction)

dice1.pFace('u')

# Buggy version:
a, b, c, d, e, f = map(int, input().split())
S = list(input())
i = 0
number1 = a
number2 = b
number3 = c
number4 = d
number5 = e
number6 = f

while i < len(S) :
    if S[i] == "N" :
        number1 = b
        number2 = f
        number3 = c
        number4 = d
        number5 = a
        number6 = e
    elif S[i] == "S" :
        number1 = e
        number2 = a
        number3 = c
        number4 = d
        number5 = f
        number6 = b
    elif S[i] == "E" :
        number1 = d
        number2 = b
        number3 = a
        number4 = f
        number5 = e
        number6 = c
    elif S[i] == "W" :
        number1 = c
        number2 = a
        number3 = f
        number4 = a
        number5 = f
        number6 = d
    a = number1
    b = number2
    c = number3
    d = number4
    e = number5
    f = number6
    i = i + 1
print(number1)


# Fixed version:
a, b, c, d, e, f = map(int, input().split())
S = list(input())
i = 0
number1 = a
number2 = b
number3 = c
number4 = d
number5 = e
number6 = f

while i < len(S) :
    if S[i] == "N" :
        number1 = b
        number2 = f
        number3 = c
        number4 = d
        number5 = a
        number6 = e
    elif S[i] == "S" :
        number1 = e
        number2 = a
        number3 = c
        number4 = d
        number5 = f
        number6 = b
    elif S[i] == "E" :
        number1 = d
        number2 = b
        number3 = a
        number4 = f
        number5 = e
        number6 = c
    elif S[i] == "W" :
        number1 = c
        number2 = b
        number3 = f
        number4 = a
        number5 = e
        number6 = d
    a = number1
    b = number2
    c = number3
    d = number4
    e = number5
    f = number6
    i = i + 1
print(number1)

# Buggy version:
dice = input().split()
direction = list(input())
dice2 = []
for i in range(len(direction)):
    dice2 = dice
    print(dice2)
    if direction[i] == 'E':
        dice = [dice2[3],dice2[1],dice2[0],dice2[5],dice2[4],dice2[2]]
        print(dice)
    elif direction[i] == 'N':
        dice = [dice2[1],dice2[5],dice2[2],dice2[3],dice2[0],dice2[4]]
        print(dice)
    elif direction[i] == 'S':
        dice = [dice2[4],dice2[0],dice2[2],dice2[3],dice2[5],dice2[1]]
        print(dice)
    else:
        dice = [dice2[2],dice2[1],dice2[5],dice2[0],dice2[4],dice2[3]]
        print(dice)
print('{0}'.format(int(dice[0])))


# Fixed version:
dice = input().split()
direction = list(input())
dice2 = []
for i in range(len(direction)):
    dice2 = dice
    if direction[i] == 'E':
        dice = [dice2[3],dice2[1],dice2[0],dice2[5],dice2[4],dice2[2]]
    elif direction[i] == 'N':
        dice = [dice2[1],dice2[5],dice2[2],dice2[3],dice2[0],dice2[4]]
    elif direction[i] == 'S':
        dice = [dice2[4],dice2[0],dice2[2],dice2[3],dice2[5],dice2[1]]
    else:
        dice = [dice2[2],dice2[1],dice2[5],dice2[0],dice2[4],dice2[3]]
print('{0}'.format(int(dice[0])))

# Buggy version:
from collections import deque

class Dice:
    def __init__(self, top, down, right, left, up, bottom):
        self.top = top
        self.bottom = bottom
        self.up = up
        self.down = down
        self.left = left
        self.right = right

    def roll(self, command):
        for c in list(command):
            if c == 'N':
                self.up, self.top, self.down, self.bottom = self.top, self.down, self.bottom, self.up
            elif c == 'S':
                self.up, self.top, self.down, self.bottom = self.bottom, self.up, self.top, self.down
            elif c == 'E':
                self.left, self.top, self.right, self.bottom = self.bottom, self.left, self.top, self.right
            elif c == 'W':
                self.left, self,top, self.right, self.bottom = self.top, self.right, self.bottom, self.left

    def pip(self):
        return self.top

if __name__ == '__main__':
    seq = list(map(int, input().split()))
    dice = Dice(*seq)
    dice.roll(input())
    print(dice.pip())



# Fixed version:
from collections import deque

class Dice:
    def __init__(self, top, down, right, left, up, bottom):
        self.top = top
        self.bottom = bottom
        self.up = up
        self.down = down
        self.left = left
        self.right = right

    def roll(self, command):
        for c in list(command):
            if c == 'N':
                self.up, self.top, self.down, self.bottom = self.top, self.down, self.bottom, self.up
            elif c == 'S':
                self.up, self.top, self.down, self.bottom = self.bottom, self.up, self.top, self.down
            elif c == 'E':
                self.left, self.top, self.right, self.bottom = self.bottom, self.left, self.top, self.right
            elif c == 'W':
                self.left, self.top, self.right, self.bottom = self.top, self.right, self.bottom, self.left

    def pip(self):
        return self.top

if __name__ == '__main__':
    seq = list(map(int, input().split()))
    dice = Dice(*seq)
    dice.roll(input())
    print(dice.pip())

# Buggy version:
def dice():
	dice = list(map(str, input().split()))
	direction = input()
	for i in range(len(direction)):
		if direction[i] == "N":
			dice[0],dice[1],dice[4],dice[5] = dice[1],dice[5],dice[0],dice[4]
		elif direction[i] == "S":
			dice[0],dice[1],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[1]
		elif direction[i] == "W":
			dice[0],dice[2],dice[3],dice[5] = dice[2],dice[5],dice[0],dice[3]
		else :
			dice[0],dice[2],dice[3],dice[5] = dice[3],dice[0],dice[5],dice[2]
	print(dice[0])


# Fixed version:
dice = list(map(str, input().split()))
direction = input()
for i in range(len(direction)):
	if direction[i] == "N":
		dice[0],dice[1],dice[4],dice[5] = dice[1],dice[5],dice[0],dice[4]
	elif direction[i] == "S":
		dice[0],dice[1],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[1]
	elif direction[i] == "W":
		dice[0],dice[2],dice[3],dice[5] = dice[2],dice[5],dice[0],dice[3]
	else :
		dice[0],dice[2],dice[3],dice[5] = dice[3],dice[0],dice[5],dice[2]
print(dice[0])

# Buggy version:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t=t
        self.f=f
        self.r=r
        self.l=l
        self.b=b
        self.u=u
    def roll(self,i):
        if d=='S':
            key=self.t
            self.t=self.b
            self.b=self.u
            self.u=self.f
            self.t=key
        elif d=='E':
            key=self.t
            self.t=self.l
            self.l=self.u
            self.u=self.r
            self.r=key
        elif d=='N':
            key=self.t
            self.t=self.f
            self.f=self.u
            self.u=self.b
            self.b=key
        else:
            key=self.t
            self.t=self.r
            self.r=self.u
            self.u=self.l
            self.l=key
t,f,r,l,b,u=map(int,input().split())
a=list(input())
dice=Dice(t,f,r,l,b,u)
for d in a:
    dice.roll(d)
print(dice.t)


# Fixed version:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t=t
        self.f=f
        self.r=r
        self.l=l
        self.b=b
        self.u=u
    def roll(self,i):
        if d=='S':
            key=self.t
            self.t=self.b
            self.b=self.u
            self.u=self.f
            self.f=key
        elif d=='E':
            key=self.t
            self.t=self.l
            self.l=self.u
            self.u=self.r
            self.r=key
        elif d=='N':
            key=self.t
            self.t=self.f
            self.f=self.u
            self.u=self.b
            self.b=key
        else:
            key=self.t
            self.t=self.r
            self.r=self.u
            self.u=self.l
            self.l=key
t,f,r,l,b,u=map(int,input().split())
a=list(input())
dice=Dice(t,f,r,l,b,u)
for d in a:
    dice.roll(d)
print(dice.t)

# Buggy version:
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.b, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top

li = list(map(int, input().split()))
D = Dice(li)
command = input()
for dir in command:
    D.rot(dir)
print(D.getTop())


# Fixed version:
class Dice():
    def __init__(self, numbers):
        self.top = numbers[0]
        self.s = numbers[1]
        self.e = numbers[2]
        self.w = numbers[3]
        self.n = numbers[4]
        self.bot = numbers[5]
    def rot(self, dir):
        top, s, e, w, n, bot = (self.top, self.s, self.e, self.w, self.n, self.bot)
        if dir == 'N':
            self.top = s
            self.s = bot
            self.e = e
            self.w = w
            self.n = top
            self.bot = n
        elif dir == 'S':
            self.top = n
            self.s = top
            self.e = e
            self.w = w
            self.n = bot
            self.bot = s
        elif dir == 'E':
            self.top = w
            self.s = s
            self.e = top
            self.w = bot
            self.n = n
            self.bot = e
        elif dir == 'W':
            self.top = e
            self.s = s
            self.e = bot
            self.w = top
            self.n = n
            self.bot = w
    def getTop(self):
        return self.top

li = list(map(int, input().split()))
D = Dice(li)
command = input()
for dir in command:
    D.rot(dir)
print(D.getTop())

# Buggy version:
num = (int, input().split())
dice = {'N':(2, 6, 3, 4, 1, 5),'E':(4, 2, 1, 6, 5, 3),'W':(3, 2, 6, 1, 5, 4),'S':(5, 1, 3, 4, 6, 2)}
for alf in input():
    num = [num[i]for i in dice[alf-1]]
print(num[0])



# Fixed version:
dice = {'N':(2, 6, 3, 4, 1, 5),'E':(4, 2, 1, 6, 5, 3),'W':(3, 2, 6, 1, 5, 4),'S':(5, 1, 3, 4, 6, 2)}
num = input().split()
for alf in input():
    num = [num[i-1]for i in dice[alf]]
print(num[0])

# Buggy version:
class Dice:
    
    def __init__(self, val):
        self.top = val[0]
        self.flat1 = val[1]
        self.flat2 = val[2]
        self.flat3 = val[3]
        self.flat4 = val[4]
        self.bottom = val[5]
        
    def doSouth(self):
        temp = self.bottom
        self.bottom = self.flat2
        self.flat2 = self.top
        self.top = temp

    def doNorth(self):
        temp = self.top
        self.top = self.flat2
        self.flat2 = self.bottom
        self.bottom = temp

    def doWest(self):
        temp = self.bottom
        self.top = self.flat3
        self.flat1 = self.top
        self.bottom = self.flat1
        self.flat3 = temp

    def doEast(self):
        temp = self.bottom
        self.top = self.flat1
        self.flat3 = self.top
        self.bottom = self.flat3
        self.flat1 = temp

def transform(dice, motion):
    if motion == 'S':
        dice.doSouth()
    elif motion == 'N':
        dice.doNorth()
    elif motion == 'W':
        dice.doWest()
    elif motion == 'E':
        dice.doEast()

N = input().split()
dice = Dice(N)
motion = input()
for i in range(len(motion)):
    transform(dice, motion[i])
print(dice.top)


# Fixed version:
class Dice:
    
    def __init__(self, val):
        self.top = val[0]
        self.flat1 = val[3]
        self.flat2 = val[1]
        self.flat3 = val[2]
        self.flat4 = val[4]
        self.bottom = val[5]
        
    def doSouth(self):
        temp = self.bottom
        self.bottom = self.flat2
        self.flat2 = self.top
        self.top = self.flat4
        self.flat4 = temp

    def doNorth(self):
        temp = self.bottom
        self.bottom = self.flat4
        self.flat4 = self.top
        self.top = self.flat2
        self.flat2 = temp

    def doWest(self):
        temp = self.top
        self.top = self.flat3
        self.flat3 = self.bottom
        self.bottom = self.flat1
        self.flat1 = temp


    def doEast(self):
        temp = self.top
        self.top = self.flat1
        self.flat1 = self.bottom
        self.bottom = self.flat3
        self.flat3 = temp
    
    def doget(self):
        list = [self.top, self.flat2, self.flat3, self.flat1, self.flat4, self.bottom]
        return(list)

def transform(dice, motion):
    if motion == 'S':
        dice.doSouth()
    elif motion == 'N':
        dice.doNorth()
    elif motion == 'W':
        dice.doWest()
    elif motion == 'E':
        dice.doEast()

N = input().split()
dice = Dice(N)
motion = input()
for i in range(len(motion)):
    transform(dice, motion[i])
print(dice.top)

# Buggy version:
ef north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List

dice = list(map(int, input().split()))
x = str(input())
y = list(x)
for i in range(len(x)):
    if y[i] == 'N':
        dice[0:5] = north(dice)
    elif y[i] == 'W':
        dice[0:5] = west(dice)
    elif y[i] == 'S':
        dice[0:5] = south(dice)
    elif y[i] == 'E':
        dice[0:5] = east(dice)
print(dice[0])



# Fixed version:
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List
 
def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
     
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List
 
def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List
 
dice = list(map(int, input().split()))
x = str(input())
y = list(x)
for i in range(len(x)):
    if y[i] == 'N':
        dice[0:5] = north(dice)
    elif y[i] == 'W':
        dice[0:5] = west(dice)
    elif y[i] == 'S':
        dice[0:5] = south(dice)
    elif y[i] == 'E':
        dice[0:5] = east(dice)
print(dice[0])