Problem: On a small planet named Bandai, a landing party of the starship Tadamigawa discovered colorful cubes traveling on flat areas of the planet surface, which the landing party named beds. A cube appears at a certain position on a bed, travels on the bed for a while, and then disappears. After a longtime observation, a science officer Lt. Alyssa Ogawa of Tadamigawa found the rule how a cube travels on a bed.

A bed is a rectangular area tiled with squares of the same size.

* One of the squares is colored red,
* one colored green,
* one colored blue,
* one colored cyan,
* one colored magenta,
* one colored yellow,
* one or more colored white, and
* all others, if any, colored black.



Initially, a cube appears on one of the white squares. The cube’s faces are colored as follows.


top  red
bottom  cyan
north  green
south  magenta
east  blue
west  yellow


The cube can roll around a side of the current square at a step and thus rolls on to an adjacent square. When the cube rolls on to a chromatically colored (red, green, blue, cyan, magenta or yellow) square, the top face of the cube after the roll should be colored the same. When the cube rolls on to a white square, there is no such restriction. The cube should never roll on to a black square.

Throughout the travel, the cube can visit each of the chromatically colored squares only once, and any of the white squares arbitrarily many times. As already mentioned, the cube can never visit any of the black squares. On visit to the final chromatically colored square, the cube disappears. Somehow the order of visits to the chromatically colored squares is known to us before the travel starts.

Your mission is to find the least number of steps for the cube to visit all the chromatically colored squares in the given order.



Input

The input is a sequence of datasets. A dataset is formatted as follows:


w d

c11 . . . cw1
.        .
.        .
.        .
c1d . . . cwd
v1v2v3v4v5v6


The first line is a pair of positive integers w and d separated by a space. The next d lines are w-character-long strings c11 . . . cw1 , . . . , c1d . . . cwd with no spaces. Each character cij is one of the letters r, g, b, c, m, y, w and k, which stands for red, green, blue, cyan, magenta, yellow, white and black respectively, or a sign #. Each of r, g, b, c, m, y and # occurs once and only once in a dataset. The last line is a six-character-long string v1v2v3v4v5v6 which is a permutation of “rgbcmy”.

The integers w and d denote the width (the length from the east end to the west end) and the depth (the length from the north end to the south end) of a bed. The unit is the length of a side of a square. You can assume that neither w nor d is greater than 30.

Each character cij shows the color of a square in the bed. The characters c11 , cw1 , c1d and cwd correspond to the north-west corner, the north-east corner, the south-west corner and the south- east corner of the bed respectively. If cij is a letter, it indicates the color of the corresponding square. If cij is a #, the corresponding square is colored white and is the initial position of the cube.

The string v1v2v3v4v5v6 shows the order of colors of squares to visit. The cube should visit the squares colored v1, v2 , v3 , v4 , v5 and v6 in this order.

The end of the input is indicated by a line containing two zeros separated by a space.

Output

For each input dataset, output the least number of steps if there is a solution, or "unreachable" if there is no solution. In either case, print it in one line for each input dataset.

Example

Input

10 5
kkkkkwwwww
w#wwwrwwww
wwwwbgwwww
kwwmcwwwkk
kkwywwwkkk
rgbcmy
10 5
kkkkkkkkkk
k#kkkkkkkk
kwkkkkkwwk
kcmyrgbwwk
kwwwwwwwwk
cmyrgb
10 5
kkkkkkkkkk
k#kkkkkkkk
kwkkkkkwkk
kcmyrgbwwk
kwwwwwwwwk
cmyrgb
0 0


Output

9
49
unreachable

Solution (in JAVA):

Solution:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Traveling Cube
public class Main{

	int[][] move = {{-1,0}, {0,1},{1,0},{0,-1}};
	Dice<Character> d;

	int getID(int s, int k){
		Dice<Character> c = d.list.get(s).copy();
		if(k==0)c.rollX(false);
		else if(k==1)c.rollY(false);
		else if(k==2)c.rollX(true);
		else c.rollY(true);
		return d.getID(c);
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		d = new Dice<Character>('r', 'c', 'm', 'g', 'b', 'y');
		d.list = d.getAllState();
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h)==0)break;
			char[][] map = new char[h][w];
			for(int i=0;i<h;i++)map[i]=sc.next().toCharArray();
			char[] order = sc.next().toCharArray();
			int si, sj;
			si = sj = -1;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(map[i][j]=='#'){
						map[i][j] = 'w';
						si = i;
						sj = j;
					}
				}
			}
			boolean[][][][] u = new boolean[h][w][24][7];
			u[si][sj][0][0] = true;
			List<int[]> l = new ArrayList<int[]>();
			l.add(new int[]{si, sj, 0, 0});
			int step = 0;
			boolean f = false;
			while(!l.isEmpty()){
				List<int[]> next = new ArrayList<int[]>();
				for(int a[]:l){
					int i = a[0];
					int j = a[1];
					int s = a[2];
					int c = a[3];
					if(c==6){
						next.clear();
						f = true;
						break;
					}
					for(int k=0;k<4;k++){
						int ni = i+move[k][0];
						int nj = j+move[k][1];
						if(0<=ni&&ni<h&&0<=nj&&nj<w){
							int ns = getID(s, k);
							char ch = d.list.get(ns).get(Dice.Face.TOP);
							if(map[ni][nj]=='w'&&!u[ni][nj][ns][c]){
								u[ni][nj][ns][c] = true;
								next.add(new int[]{ni, nj, ns, c});
							}
							else if(map[ni][nj]==order[c]&&order[c]==ch&&!u[ni][nj][ns][c+1]){
								u[ni][nj][ns][c+1] = true;
								next.add(new int[]{ni, nj, ns, c+1});
							}
						}
					}
				}
				step++;
				l = next;
			}
			System.out.println(f?--step:"unreachable");
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	static class Dice <T>{
		public T[] id;
		enum Face{TOP, BOTTOM, FRONT, BACK, RIGHT, LEFT};
		List<Dice<T>> list;

		public T get(Face f){
			return id[f.ordinal()];
		}

		public Dice<T> copy(){
			return new Dice<T>(id[0], id[1], id[2], id[3], id[4], id[5]);
		}

		public int getID(Dice<T> d){
			for(int i=0;i<24;i++)if(d.equals(list.get(i)))return i;
			return -1;
		}

		public Dice() {
			@SuppressWarnings("unchecked")
			T[] tid = (T[])new Object[6];
			id = tid;
		}

		public Dice(T top, T bottom, T front, T back, T right, T left) {
			@SuppressWarnings("unchecked")
			T[] tid = (T[])new Object[6];
			id = tid;
			id[Face.TOP.ordinal()] = top;
			id[Face.BOTTOM.ordinal()]= bottom;
			id[Face.FRONT.ordinal()] = front;
			id[Face.BACK.ordinal()] = back;
			id[Face.RIGHT.ordinal()] = right;
			id[Face.LEFT.ordinal()] = left;
		}

		//true: Xツ篠イツ陛サツ古シツづ可偲ィツ前ツづ可転ツつェツつキ
		//false: Xツ篠イツ陛サツ古シツづ可可慊づ可転ツつェツつキ
		void rollX(boolean isReverse) {
			if(!isReverse) roll(Face.TOP, Face.FRONT, Face.BOTTOM, Face.BACK);
			else roll(Face.TOP, Face.BACK, Face.BOTTOM, Face.FRONT);
		}

		//true: Yツ篠イツ陛サツ古シツづ可債カツづ鳴転ツつェツつキ
		//false: Yツ篠イツ陛サツ古シツづ可右ツづ鳴転ツつェツつキ
		void rollY(boolean isReverse) {
			if(!isReverse) roll(Face.TOP, Face.LEFT, Face.BOTTOM, Face.RIGHT);
			else roll(Face.TOP, Face.RIGHT, Face.BOTTOM, Face.LEFT);
		}

		//true: Zツ篠イツ陛サツ古シツづ可右ツづ鳴嘉アツつキ
		//false: Zツ篠イツ陛サツ古シツづ可債カツづ鳴嘉アツつキ
		void rollZ(boolean isReverse) {
			if(!isReverse) roll(Face.FRONT, Face.LEFT, Face.BACK, Face.RIGHT);
			else roll(Face.FRONT, Face.RIGHT, Face.BACK, Face.LEFT);
		}

		private void roll(Face w, Face x, Face y, Face z) {
			T tmp = id[w.ordinal()];
			id[w.ordinal()] = id[x.ordinal()];
			id[x.ordinal()] = id[y.ordinal()];
			id[y.ordinal()] = id[z.ordinal()];
			id[z.ordinal()] = tmp;
		}

		@Override
		public boolean equals(Object o) {
			if(!(o instanceof Dice<?>))return false;
			@SuppressWarnings("unchecked")
			Dice<T> d = (Dice<T>)o;
			for(Face f : Face.values()){
				if(!id[f.ordinal()].equals(d.id[f.ordinal()])){
					return false;
				}
			}
			return true;
		}

		List<Dice<T>> getAllState(){
			List<Dice<T>> lst = new ArrayList<Dice<T>>();
			for(int i = 0; i < 6; i++){
				for(int j = 0; j < 4; j++){
					lst.add(new Dice<T>(id[Face.TOP.ordinal()], id[Face.BOTTOM.ordinal()], id[Face.FRONT.ordinal()], id[Face.BACK.ordinal()], id[Face.RIGHT.ordinal()], id[Face.LEFT.ordinal()]));
					rollZ(false);
				}
				if(i%2 == 1) rollY(false);
				else rollX(false);
			}
			return lst;
		}
	}
}