#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
//l r f b d u
//0 1 2 3 4 5
int go[4][6] = {
    {5, 4, 2, 3, 0, 1},
    {0, 1, 5, 4, 2, 3},
    {0, 1, 4, 5, 3, 2},
    {4, 5, 2, 3, 1, 0}
};
const int N(65555);
const int LOG(16);
int x[LOG], y[LOG];
char st[555];
int a[6], b[6], tp[555], lg2[N];
vector<pair<pair<int, int>,int> > vec[LOG];
int cnf[LOG][LOG], totcnf[N][LOG], ic[N][LOG], ans[N];
int main() {
    tp['R'] = 0;
    tp['B'] = 1;
    tp['F'] = 2;
    tp['L'] = 3;
    int n;
    for(;;) {
        scanf("%d", &n);
        if(!n) {
            break;
        }
        for(int i(0); i < n; i++) {
            scanf("%d%d", &x[i], &y[i]);
            for(int j(0); j < 6; j++) {
                scanf("%d", &a[j]);
            }
            scanf("%s", st);
            int len(strlen(st));
            vec[i].clear();
            for(int j(0); j <= len; j++) {
                //printf("%d %d %d %d\n", i, x[i], y[i], a[4]);
                vec[i].push_back(make_pair(make_pair(x[i], y[i]), a[4]));
                if(j != len) {
                    for(int k(0); k < 6; k++) {
                        b[go[tp[st[j]]][k]] = a[k];
                    }
                    memcpy(a, b, sizeof(b));
                    x[i] += dx[tp[st[j]]];
                    y[i] += dy[tp[st[j]]];
                }
            }
            for(int j(0); j + 1 < (int)vec[i].size(); j++) {
                bool flag(false);
                for(int k(j + 1); k < (int)vec[i].size(); k++) {
                    if(vec[i][j].first == vec[i][k].first) {
                        flag = true;
                        break;
                    }
                }
                if(flag) {
                    vec[i].erase(vec[i].begin() + j);
                    j--;
                }
            }
            for(int j(0); j < i; j++) {
                cnf[j][i] = 0;
                cnf[i][j] = 0;
                for(int k(0); k < (int)vec[i].size(); k++) {
                    for(int l(0); l < (int)vec[j].size(); l++) {
                        if(vec[i][k].first == vec[j][l].first) {
                            cnf[j][i] |= 1 << k;
                            cnf[i][j] |= 1 << l;
                        }
                    }
                }
                //printf("cnf[%d][%d] = %d\n", i, j, cnf[i][j]);
            }
        }
        for(int i(0); i < n; i++) {
            lg2[1 << i] = i;
        }
        for(int msk(0); msk < (1 << n); msk++) {
            for(int i(0); i < n; i++) {
                if((msk & (1 << i)) == 0) {
                    ic[msk][i] = 0;
                    totcnf[msk][i] = msk == 0 ? 0 : totcnf[msk - (msk & -msk)][i] | cnf[lg2[msk & -msk]][i];
                    for(int j(0); j < (int)vec[i].size(); j++) {
                        ic[msk][i] += (totcnf[msk][i] & (1 << j)) ? 0 : vec[i][j].second;
                    }
                    //printf("ic[%d][%d] = %d\n", msk, i, ic[msk][i]);
                }
            }
        }
        memset(ans, 0, sizeof(ans));
        for(int msk(0); msk < (1 << n); msk++) {
            for(int i(0); i < n; i++) {
                if((msk & (1 << i)) == 0) {
                    ans[msk | (1 << i)] = max(ans[msk | (1 << i)], ans[msk] + ic[msk][i]);
                }
            }
        }
        printf("%d\n", ans[(1 << n) - 1]);
    }
}

Measured memory_bytes: 7516