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<queue>
#include<deque>
#include<vector>
#include<algorithm>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 40

using namespace std;

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  dice() {
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
    id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator==(const dice<T>& b) const {
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
      a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
      a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const dice& di) {
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    T tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

struct P
{
  int x,y;
  P(int x=inf,int y=inf):x(x),y(y){}
};



FACE face[] = {TOP,BOTTOM,FRONT,BACK,LEFT,RIGHT};
string output[]= {"TOP","BOTTOM","FRONT","BAXK","LEFT","RIGHT"};
int value[] = {  1,     6,    2,   5,   3,    4};
char COLOR[] = {'r','c','m','g','y','b'};
int W,H;
char G[MAX][MAX];
bool used[6][MAX][MAX][6][6];
int mincost[6];
vector<P> colors;
string perm;
P Index[200];
int number[200];
int dx[] = {0,-1,0,1};
int dy[] = {+1,0,-1,0};
int ANS;
bool OK;
bool added[6];

struct Pox
{
  int depth,x,y,cost;
  dice<char> die;
  Pox(int depth=inf,int x=inf,int y=inf,int cost=inf):depth(depth),x(x),y(y),cost(cost){}
  bool operator < (const Pox& a)const
  {
    if(depth != a.depth)
      return depth > a.depth;
    if(cost != a.cost)
      return cost > a.cost;
    if(x != a.x)
      return x > a.x;
    return y > a.y;
  }
};



void compute(int sx,int sy)
{

  dice<char> ini;
  rep(i,6)rep(j,MAX)rep(k,MAX)rep(l,6)rep(x,6)used[i][j][k][l][x] = false;

  rep(i,6)ini[face[i]] = COLOR[i];
  used[0][sy][sx][number[ini[TOP]]][number[ini[FRONT]]] = true;

  priority_queue<Pox> deq;  
  Pox poxas7 = Pox(0,sx,sy,0);
  poxas7.die = ini;
  deq.push(poxas7);

  while(!deq.empty())
    {
      Pox pox = deq.top(); deq.pop();

      if(pox.depth+1 >= 7)break;
      char cur = (pox.depth==0?'#':perm[pox.depth-1]);
      char next = perm[pox.depth];

      //cout << pox.depth << " (" << pox.x << "," << pox.y << ") cost : " << pox.cost << " TOP : " << pox.die[TOP] << " G : " << G[pox.y][pox.x] << " cur " << cur << "next " << next<< endl;  

      if(G[pox.y][pox.x] == next && pox.die[TOP] == next)
	{

	  //assert(mincost[number[next]] != inf && mincost[number[next]] > pox.cost);
	  //if(mincost[number[next]] < pox.cost)continue;
	  //cout << mincost[number[next]] << "-------------------------- add " << pox.cost << endl;
	  mincost[number[next]] = pox.cost;
	  if(pox.depth >= 5)
	    {
	      OK = true;
	      cout << pox.cost << endl;
	      return;
	    }
	  else
	    {
	      pox.depth++;
	      deq.push(pox);
	      continue;
	    }
	}
      /*
      rep(i,4)
	{
	  int nx = pox.x + dx[i];
	  int ny = pox.y + dy[i];
	  if(!(0 <= nx && nx < W && 0 <= ny && ny < H))continue;
	  if(G[ny][nx] == 'k')continue;
	  if(G[ny][nx] != 'w' && G[ny][nx] != next)continue;

	  dice<char> die = pox.die;
	  if(i == 0)die.roll_x();
	  if(i == 1)rep(j,3)die.roll_y();
	  if(i == 2)rep(j,3)die.roll_x();
	  if(i == 3)die.roll_y();

	  if(G[ny][nx] != 'w' && next != die[TOP])continue;
	  if(used[pox.depth][ny][nx][number[die[TOP]]][number[die[FRONT]]])continue;

	  used[pox.depth][ny][nx][number[die[TOP]]][number[die[FRONT]]] = true;
	  poxas7 = Pox(pox.depth,nx,ny,pox.cost+1);
	  poxas7.die = die;
	  deq.push(poxas7);

	}
      */
      rep(i,4)
	{
	  int nx = pox.x + dx[i];
	  int ny = pox.y + dy[i];
	  dice<char> die = pox.die;
	  if(!( 0 <= nx && nx < W && 0 <= ny && ny < H ))continue;
	  if(G[ny][nx] == 'k')continue;
	  if(G[ny][nx] != 'w' && G[ny][nx] != next)continue;
 
	  if(i == 0)die.roll_x();
	  if(i == 1)rep(j,3)die.roll_y();
	  if(i == 2)rep(j,3)die.roll_x();
	  if(i == 3)die.roll_y();
 
	  if(used[pox.depth][ny][nx][number[die[TOP]]][number[die[FRONT]]] )continue;
	  if(G[ny][nx] != 'w')if(G[ny][nx] != die[TOP])continue;
       
	  used[pox.depth][ny][nx][number[die[TOP]]][number[die[FRONT]]] = true;
	  poxas7 = Pox(pox.depth,nx,ny,pox.cost+1);
	  poxas7.die = die;
	  deq.push(poxas7);
 
 
	}
 
    }

}


int main()
{
  rep(i,6)number[COLOR[i]] = i;
  while(cin >> W >> H,W|H)
    {

      colors.clear();
      colors.resize(6);
      int sx,sy;
      rep(i,H)rep(j,W)
	{
	  cin >> G[i][j];
	  if(G[i][j]=='#')sx = j,sy = i,G[i][j] = 'w';
	  if(G[i][j]=='r')Index['r'] = P(j,i);
	  if(G[i][j]=='c')Index['c'] = P(j,i);
	  if(G[i][j]=='g')Index['g'] = P(j,i);
	  if(G[i][j]=='m')Index['m'] = P(j,i);
	  if(G[i][j]=='b')Index['b'] = P(j,i);
	  if(G[i][j]=='y')Index['y'] = P(j,i);
	}

      cin >> perm;
      ANS = 0;
      OK = false;
      rep(i,6)added[i] = false,mincost[i] = inf;
      compute(sx,sy);
      ANS = 0;
      rep(i,6)ANS+=mincost[i];
      if(!OK)cout << "unreachable"<< endl;
      //if(OK)cout << ANS << endl;
      //else  cout << "unreachable" << endl;
    }
  return 0;
}