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 CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

// AOJ1057(UAPC2010G) Ég¦éÀ.Q½ÊÅTCR]ª·Æ«g¦»¤.
// TCRÍi¯¶TCRÈçj×Ú·éQÊÌlðè·êÎü«ªÜé©çAdi.t*7+di.sÅêÓÉèÜé.
int dy[]={-1,0,1,0};
int dx[]={0,-1,0,1};
struct dice{
	int t,b,n,s,e,w;              // top bottom north south east west
	int y,x;
  int i;
  
	void roll(int d)
	{
		int tmp;
		y+=dy[d],x+=dx[d];
		
		if(d==0) {
			tmp=t; t=s; s=b; b=n; n=tmp;
		}else if(d==1) {
			tmp=t; t=e; e=b; b=w; w=tmp;
		}else if(d==2) {
			tmp=t; t=n; n=b; b=s; s=tmp;
		}else {
			tmp=t; t=w; w=b; b=e; e=tmp;
		}
	}
};

string route;
int dis[6][6][30][30][6];

int w,h;
map<char, int> mp;

char ba[30][30];

int solve(dice di) {
  queue<dice> Q;
  Q.push(di);
  memset(dis,-1,sizeof(dis));

  dis[di.t][di.s][di.y][di.x][0] = 0;
  
  while(!Q.empty()) {
    dice now = Q.front();
    Q.pop();
    // if (dis[now]) continue;
    //dis[now] = 1;
    //cout << now.i << endl;
    //cout << now.x << " " << now.y << " " << now.t << endl;
    // cout << dis[now.t][now.s][now.y][now.x]  << endl;
    if (now.i == 6) {
      //cout << dis[now.t][now.s][now.y][now.x][now.i] << endl;
      return dis[now.t][now.s][now.y][now.x][now.i];
    }
    if (ba[now.y][now.x] == route[now.i]) {
      dis[now.t][now.s][now.y][now.x][now.i+1] = dis[now.t][now.s][now.y][now.x][now.i];
      now.i++;
      Q.push(now);
      continue;
    }
    
    REP(d, 4) {
      dice tmp = now;
      tmp.roll(d);

      if (tmp.x<0||tmp.x>=w||tmp.y<0||tmp.y>=h) continue;
      if (!(ba[tmp.y][tmp.x] == route[now.i] && tmp.t == mp[route[now.i]]))
        if (ba[tmp.y][tmp.x] != 'w') continue;
//      cout << tmp.x << " " << tmp.y << endl;
      if (dis[tmp.t][tmp.s][tmp.y][tmp.x][tmp.i]!=-1) continue;
//      cout << "ok" << endl;
      
      dis[tmp.t][tmp.s][tmp.y][tmp.x][tmp.i] = dis[now.t][now.s][now.y][now.x][now.i] + 1;
      Q.push(tmp);
    }
  }
  return -1;
}

int main() {
  string s = "rcgmby";
  REP(i, 6) mp[s[i]] = i;
  while(cin >> w >> h, w||h) {
    int sx,sy;
    int colorx[6], colory[6];
    REP(i, h) {
      REP(j, w) {
        cin >> ba[i][j];
        if (ba[i][j] == '#') {
          sy = i;
          sx = j;
          ba[i][j] = 'w';
        }
        if (mp.count(ba[i][j])) {
          colory[mp[ba[i][j]]] = i;
          colorx[mp[ba[i][j]]] = j;
        }
      }
    }
    cin >> route;
    int res = 0;
    dice di;
    di.t = 0;
    di.b = 1;
    di.n = 2;
    di.s = 3;
    di.e = 4;
    di.w = 5;
    di.x = sx;
    di.y = sy;
    di.i = 0;
    int tmp = solve(di);
    if (tmp == -1)
      cout << "unreachable" << endl;
    else
      cout << tmp << endl;
  }
}