#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


class Dice{
public:

	void roll(char dst){
		for(int i = 0; i < 6; i++) work[i] = number[i];
		switch(dst){
		case 'R':
			setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'F':
			setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'B':
			setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'L':
			setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	char getTop(){
		return number[0];
	}

	char getEast(){
		return number[2];
	}

	char getNorth(){
		return number[1];
	}

	char getWest(){
		return number[3];
	}

	char getBottom(){
		return number[5];
	}

	char getSouth(){
		return number[4];
	}

	void setNumber(int w0,int w1,int w2,int w3,int w4,int w5){
		number[0] = w0;
		number[1] = w1;
		number[2] = w2;
		number[3] = w3;
		number[4] = w4;
		number[5] = w5;
	}

	void setFirst(int left,int right,int front,int back,int down,int up){
		number[0] = up;
		number[1] = back;
		number[2] = right;
		number[3] = left;
		number[4] = front;
		number[5] = down;
	}

	int number[6];
	int work[6];
};

struct Info{
	int x,y,value,all_index;
};

struct Data{
	Info loc;
	int state;
};

int N;
int POW[17];
int dice_index[15]; //サイコロが転がるマスの数
int table_index;
int dp[32768];
Info info[15][32];
char buf[31];
Data table[500]; //サイコロが転がり得るマスの集計表



void func(){

	for(int i = 0; i < N; i++)dice_index[i] = 0;

	int current_x,current_y;
	int left,right,front,back,down,up;

	Dice dice;
	bool FLG;

	//サイコロの情報を取得
	for(int i = 0; i < N; i++){
		scanf("%d %d",&current_x,&current_y);

		scanf("%d %d %d %d %d %d",&left,&right,&front,&back,&down,&up);
		dice.setFirst(left,right,front,back,down,up);

		info[i][dice_index[i]].x = current_x;
		info[i][dice_index[i]].y = current_y;
		info[i][dice_index[i]].value = dice.getBottom();

		dice_index[i]++;

		scanf("%s",buf);

		for(int k = 0; buf[k] != '\0'; k++){

			dice.roll(buf[k]); //ダイスを転がす

			switch(buf[k]){
			case 'L':
				current_x--;
				break;
			case 'R':
				current_x++;
				break;
			case 'F':
				current_y--;
				break;
			case 'B':
				current_y++;
				break;
			}


			//既に訪れたことのあるマスか調べる
			FLG = false;

			for(int a = 0; a < dice_index[i]; a++){
				if(info[i][a].x == current_x && info[i][a].y == current_y){
						info[i][a].value = dice.getBottom(); //新しい値で上書き
						FLG = true;
						break;
				}
			}

			if(!FLG){
				info[i][dice_index[i]].x = current_x;
				info[i][dice_index[i]].y = current_y;
				info[i][dice_index[i]].value = dice.getBottom();

				dice_index[i]++;
			}
		}
	}

	//N個のサイコロ情報を統合する
	table_index = 0;
	for(int i = 0; i < 500; i++)table[i].state = 0;

	for(int i = 0; i < N; i++){ //15
		for(int k = 0; k < dice_index[i]; k++){ //31

			FLG = false;
			for(int a = 0; a < table_index; a++){
				if(table[a].loc.x == info[i][k].x && table[a].loc.y == info[i][k].y){ //テーブルに場所が登録済の場合
					table[a].state += POW[i]; //マス毎に、サイコロの集合を持つ
					info[i][k].all_index = a; //逆引きインデックス
					FLG = true;
					break;
				}
			}

			if(!FLG){
				table[table_index].loc.x = info[i][k].x;
				table[table_index].loc.y = info[i][k].y;
				table[table_index].state += POW[i];
				info[i][k].all_index = table_index;
				table_index++;
			}
		}
	}

	for(int state = 0; state < POW[N]; state++)dp[state] = 0;

	int sum,tmp_index,all_state;
	int next_state,next_value;

	 //★★操作を逆順にして考える★★
	for(int state = 0; state < POW[N]; state++){ //既に転がったサイコロの集合
		for(int dice = 0; dice < N; dice++){
			if(state & (1 << dice))continue;	//転がし済ならSKIP
			sum = 0;
			//あるサイコロについて、既に転がったサイコロとは重ならないマスの値の総和を求める
			for(int i = 0; i < dice_index[dice]; i++){
				tmp_index = info[dice][i].all_index;
				all_state = table[tmp_index].state;

				if(!(all_state & state)){ //そのマスを転がる自分を含めた集合と、既に転がったサイコロの集合との論理積が0の場合:自分がそのマスを初カバー
					sum += info[dice][i].value;
				}
			}
			next_state = state+POW[dice];
			next_value = dp[state]+sum;
			dp[next_state] = max(dp[next_state],next_value);
		}
	}

	printf("%d\n",dp[POW[N]-1]);
}

int main(){

	for(int i = 0; i < 17; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3452