Language: C++

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/




struct Dice
{
	int top, bottom, right, left, front, back;
	int x, y;
	string s;
	Dice(int t, int bt, int r, int l, int f, int bk, int x, int y, string s) : top(t), bottom(bt), right(r), left(l), front(f), back(bk), x(x), y(y), s(s) { ; };
	void to_front() 
	{
		int t = front;
		front = bottom;
		bottom = back;
		back = top;
		top = t;
	}
	void to_back() { REP(i, 3) to_front(); }
	void to_right() 
	{
		int t = right;
		right = top;
		top = left;
		left = bottom;
		bottom = t;
	}
	void to_left() { REP(i, 3) to_right(); }
};

int n;
vector<Dice> v;
int vis[5000][5000];
int dp[1 << 16];

int solve(int bit)
{
	if (bit == (1 << n) - 1) return 0;
	if (dp[bit] >= 0) return dp[bit];
	int res = 0;
	REP(i, n)
	{
		if ((bit >> i) & 1) continue;
		int nbit = bit | (1 << i);
		int sum = 0;
		int x = v[i].x, y = v[i].y;
		string s = v[i].s;
		if ((nbit | vis[x][y]) == nbit) sum += v[i].bottom;
		for (auto j : s)
		{
			if (j == 'L')
			{
				x--;
				v[i].to_left();
			}
			if (j == 'R')
			{
				x++;
				v[i].to_right();
			}
			if (j == 'F')
			{
				y++;
				v[i].to_front();
			}
			if (j == 'B')
			{
				y--;
				v[i].to_back();
			}
			if ((nbit | vis[x][y]) == nbit) sum += v[i].bottom;
		}
		chmax(res, solve(nbit) + sum);
	}
	return dp[bit] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	while (cin >> n, n)
	{
		MS(vis, 0);
		MS(dp, -1);
		v.clear(); v.resize(n);
		REP(i, n)
		{
			int x, y, l, r, f, b, d, u;
			cin >> x >> y >> l >> r >> f >> b >> d >> u;
			x += 2000, y += 2000;
			string s; cin >> s;
			v.emplace_back(u, d, r, l, f, b, x, y, s);
		}
		REP(i, n)
		{
			int x = v[i].x, y = v[i].y;
			string s = v[i].s;
			vis[x][y] |= 1 << i;
			for(auto j : s)
			{
				if (j == 'L') x--;
				if (j == 'R') x++;
				if (j == 'F') y++;
				if (j == 'B') y--;
				vis[x][y] |= 1 << i;
			}
		}
		cout << solve(0) << endl;
	}
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/stl_tempbuf.h:61,
                 from /usr/include/c++/14/bits/stl_algo.h:69,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = Dice; _Args = {}]':
/usr/include/c++/14/bits/stl_uninitialized.h:643:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Dice*; _Size = long unsigned int; bool _TrivialValueType = false]'
  643 |                 std::_Construct(std::__addressof(*__cur));
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:712:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Dice*; _Size = long unsigned int]'
  710 |       return __uninitialized_default_n_1<__is_trivial(_ValueType)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |                                          && __can_fill>::
      |                                          ~~~~~~~~~~~~~~~~
  712 |         __uninit_default_n(__first, __n);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:779:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = Dice*; _Size = long unsigned int; _Tp = Dice]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:821:35:   required from 'void std::vector<_Tp, _Alloc>::_M_default_append(size_type) [with _Tp = Dice; _Alloc = std::allocator<Dice>; size_type = long unsigned int]'
  821 |                 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
  822 |                                                  __n, _M_get_Tp_allocator());
      |                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1016:4:   required from 'void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = Dice; _Alloc = std::allocator<Dice>; size_type = long unsigned int]'
 1016 |           _M_default_append(__new_size - size());
      |           ^~~~~~~~~~~~~~~~~
a.cc:103:22:   required from here
  103 |                 v.clear(); v.resize(n);
      |                            ~~~~~~~~^~~
/usr/include/c++/14/bits/stl_construct.h:119:7: error: no matching function for call to 'Dice::Dice()'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:28:9: note: candidate: 'Dice::Dice(int, int, int, int, int, int, int, int, std::string)'
   28 |         Dice(int t, int bt, int r, int l, int f, int bk, int x, int y, string s) : top(t), bottom(bt), right(r), left(l), front(f), back(bk), x(x), y(y), s(s) { ; };
      |         ^~~~
a.cc:28:9: note:   candidate expects 9 arguments, 0 provided
a.cc:23:8: note: candidate: 'Dice::Dice(const Dice&)'
   23 | struct Dice
      |        ^~~~
a.cc:23:8: note:   candidate expects 1 argument, 0 provided
a.cc:23:8: note: candidate: 'Dice::Dice(Dice&&)'
a.cc:23:8: note:   candidate expects 1 argument, 0 provided