#include <iostream>
#include <vector>
#include <tuple>
#include <map>
#include <algorithm>
using namespace std;

using P = pair<int,int>; //x,y;
using T = tuple<int,int,int>; //x,y,b
int main(){
    map<P,int> overlap;//int??????????????°?????????
    map<P,int> Mov[15];
    int N;
    while(cin>>N,N){
        overlap.clear();
        for(int i=0;i<15;i++) Mov[i].clear();
        for(int i=0;i<N;i++){
            int x,y;
            cin>>x>>y;
            int l,r,f,b,d,u;
            cin>>l>>r>>f>>b>>d>>u;
            string rot;
            cin>>rot;
            overlap[P(x,y)]|=(1<<i);
            Mov[i][P(x,y)]=d;
            // cout<<d<<endl;
            for(auto c:rot){
                int temp=d;
                switch(c){
                    case 'L':
                        d=l;l=u;u=r;r=temp;
                        x--;
                        break;
                    case 'R':
                        d=r;r=u;u=l;l=temp;
                        x++;
                        break;
                    case 'B':
                        d=b;b=u;u=f;f=temp;
                        y++;
                        break;
                    case 'F':
                        d=f;f=u;u=b;b=temp;
                        y--;
                        break;
                    default:
                        break;
                }
                // cout<<d<<endl;
                overlap[P(x,y)]|=(1<<i);
                Mov[i][P(x,y)]=d;
            }
        }
        int dp[1<<N];
        fill(dp,dp+(1<<N),0);
        for(int b=0;b<(1<<N);b++){
            for(int i=0;i<N;i++){
                if(b&(1<<i)) continue;
                int bb=b|(1<<i);
                int diff=0;
                for(auto p:Mov[i]){
                    int x,y,d; tie(x,y)=p.first; d=p.second;
                    if(overlap[P(x,y)]&b) continue;
                    else diff+=d;
                }
                dp[bb]=max(dp[bb],dp[b]+diff);
            }
        }
        cout<<dp[(1<<N)-1]<<endl;
    }

    return 0;
}