human
Bob programmed a robot to navigate through a 2d maze.

The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.

There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.

The robot can only move up, left, right, or down.

When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.

The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.

Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.

Input

The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.

The next n lines will contain exactly m characters each, denoting the maze.

Each character of the maze will be '.', '#', 'S', or 'E'.

There will be exactly one 'S' and exactly one 'E' in the maze.

The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.

Output

Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.

Examples

Input

5...
Solve the task in PYTHON3.
 Write me a Python program to determine the number of mappings of digits to directions that would lead the robot to the exit?
assistant
#Here is Python program to determine the number of mappings of digits to directions that would lead the robot to the exit.

class Move:

    def __init__(self, dx, dy):
        self.dx = dx
        self.dy = dy

class Labyrinth:

    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.start_x = 0
        self.start_y = 0
        self.final_x = 0
        self.final_y = 0
        self.cells = []
        self.commands = []

    def add_line(self, line: str):
        cells_in_line = []
        for i in range(len(line)):
            char = line[i]
            if char == '.':
                cells_in_line.append(True)
            elif char == '#':
                cells_in_line.append(False)
            elif char == 'S':
                cells_in_line.append(True)
                self.start_x = i
                self.start_y = len(self.cells)
            elif char == 'E':
                cells_in_line.append(True)
                self.final_x = i
                self.final_y = len(self.cells)
        self.cells.append(cells_in_line)

    def add_commands(self, line: str):
        for i in range(len(line)):
            self.commands.append(int(line[i]))

    def test(self, moves_case: list):
        pos_x = self.start_x
        pos_y = self.start_y
        for cmd_id in self.commands:
            move = moves_case[cmd_id]  # type: Move
            pos_x += move.dx
            pos_y += move.dy
            if pos_x == self.final_x and pos_y == self.final_y:
                return True
            if pos_x < 0 or pos_x >= self.width or pos_y < 0 or pos_y >= self.height:
                return False
            if not self.cells[pos_y][pos_x]:
                return False
        return False

data = input().split()
lab = Labyrinth(int(data[1]), int(data[0]))
for y in range(lab.height):
    lab.add_line(input())
lab.add_commands(input())
move_up = Move(0, -1)
move_down = Move(0, 1)
move_left = Move(-1, 0)
move_right = Move(1, 0)

def gen_cases_3(m1, m2, m3):
    return [
        [m1, m2, m3],
        [m1, m3, m2],
        [m2, m1, m3],
        [m2, m3, m1],
        [m3, m1, m2],
       ...