#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int h, w;
		cin >> h >> w;

		char m[32][32];
		CLEAR(m, '#');
		for (int y = 1; y <= h; ++y)
		{
			cin >> m[y] + 1;
			m[y][w + 1] = '#';
		}

		const char* dd = "v>^<";
		int x, y, dir;
		for (int yy = 1; yy <= h; ++yy)
			for (int xx = 1; xx <= w; ++xx)
				if (strchr(dd, m[yy][xx]))
				{
					x = xx, y = yy;
					dir = strchr(dd, m[yy][xx]) - dd;
					m[yy][xx] = '.';
				}

		int n;
		string s;
		cin >> n >> s;
		for (int i = 0; i < n; ++i)
		{
			char c = s[i];

			const char* dc = "DRUL";
			if (strchr(dc, c))
			{
				dir = strchr(dc, c) - dc;
				int tx = x + dx[dir], ty = y + dy[dir];
				if (m[ty][tx] == '.')
					x = tx, y = ty;
			}
			else
			{
				int tx = x + dx[dir], ty = y + dy[dir];
				while (m[ty][tx] != '#')
				{
					if (m[ty][tx] == '*')
					{
						m[ty][tx] = '.';
						break;
					}
					tx += dx[dir], ty += dy[dir];
				}
			}
		}

		m[y][x] = dd[dir];

		for (int yy = 1; yy <= h; ++yy)
		{
			for (int xx = 1; xx <= w; ++xx)
				cout << m[yy][xx];
			cout << endl;
		}
		if (T)
			cout << endl;
	}
}