#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll t;
cin >> t;
while (t--) {
ll n, m;
cin >> n >> m;
char s[n + m - 2];
scanf("%s", s);
vector<vector<ll>> a(n, vector<ll>(m));
vector<ll> rowSum(n, 0);
vector<ll> colSum(m, 0);
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
cin >> a[i][j];
rowSum[i] += a[i][j];
colSum[j] += a[i][j];
}
}
ll x = 0, y = 0;
for (ll i = 0; i < n + m - 1; i++) {
if (s[i] == 'D') {
a[x][y] = -rowSum[x];
colSum[y] += a[x][y];
x++;
} else {
a[x][y] = -colSum[y];
rowSum[x] += a[x][y];
y++;
}
}
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCgppbnQgbWFpbigpIHsKICAgIGxsIHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pIHsKICAgICAgICBsbCBuLCBtOwogICAgICAgIGNpbiA+PiBuID4+IG07CiAgICAgICAgY2hhciBzW24gKyBtIC0gMl07CiAgICAgICAgc2NhbmYoIiVzIiwgcyk7CiAgICAgICAgdmVjdG9yPHZlY3RvcjxsbD4+IGEobiwgdmVjdG9yPGxsPihtKSk7CiAgICAgICAgdmVjdG9yPGxsPiByb3dTdW0obiwgMCk7CiAgICAgICAgdmVjdG9yPGxsPiBjb2xTdW0obSwgMCk7CgogICAgICAgIGZvciAobGwgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IG07IGorKykgewogICAgICAgICAgICAgICAgY2luID4+IGFbaV1bal07CiAgICAgICAgICAgICAgICByb3dTdW1baV0gKz0gYVtpXVtqXTsKICAgICAgICAgICAgICAgIGNvbFN1bVtqXSArPSBhW2ldW2pdOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBsbCB4ID0gMCwgeSA9IDA7CiAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IG4gKyBtIC0gMTsgaSsrKSB7CiAgICAgICAgICAgIGlmIChzW2ldID09ICdEJykgewogICAgICAgICAgICAgICAgYVt4XVt5XSA9IC1yb3dTdW1beF07CiAgICAgICAgICAgICAgICBjb2xTdW1beV0gKz0gYVt4XVt5XTsgCiAgICAgICAgICAgICAgICB4Kys7ICAKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGFbeF1beV0gPSAtY29sU3VtW3ldOwogICAgICAgICAgICAgICAgcm93U3VtW3hdICs9IGFbeF1beV07CiAgICAgICAgICAgICAgICB5Kys7IAogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAobGwgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IG07IGorKykgewogICAgICAgICAgICAgICAgY291dCA8PCBhW2ldW2pdIDw8ICIgIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiAwOwp9
NAozIDMKRFJSRAowIDIgMwowIDAgMAozIDEgMAo0IDUKRFJSUlJERAowIDEgMCAyIDMKMCAwIDAgMCAwCi0xIDAgLTMgLTMgMAowIDAgMCAtMSAwCjIgMwpSUkQKMCAwIDAKMCAxIDAKNSA1CkRERERSUlJSCjAgMjUgMiA5IDExCjAgNiAxMyAyMCAyMgowIDE3IDI0IDEgOAowIDMgMTAgMTIgMTkKMCAwIDAgMCAwCg==
4
3 3
DRRD
0 2 3
0 0 0
3 1 0
4 5
DRRRRDD
0 1 0 2 3
0 0 0 0 0
-1 0 -3 -3 0
0 0 0 -1 0
2 3
RRD
0 0 0
0 1 0
5 5
DDDDRRRR
0 25 2 9 11
0 6 13 20 22
0 17 24 1 8
0 3 10 12 19
0 0 0 0 0