#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int main() {
int t;
cin >> t;
while(t--){
ll n, m;
string s;
cin >> n >> m >> s;
vector<vector<int> > a(n, vector<int>(m));
vector<int> sumc(n);
vector<int> sumr(m);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
sumc[i] += a[i][j];
sumr[j] += a[i][j];
}
}
int i = 0, j = 0;
for(int x = 0; x < s.size(); x++){
if(s[x] == 'D'){
a[i][j] = - sumc[i];
sumc[i] += a[i][j];
sumr[j] += a[i][j];
i++;
}
if(s[x] == 'R'){
a[i][j] = - sumr[j];
sumc[i] += a[i][j];
sumr[j] += a[i][j];
j++;
}
}
a[i][j] = -sumr[j];
cout << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout << a[i][j] << " ";
}
cout << endl;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmludCBtYWluKCkgewogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgbGwgbiwgbTsKICAgICAgICBzdHJpbmcgczsKICAgICAgICBjaW4gPj4gbiA+PiBtID4+IHM7CiAgICAgICAgdmVjdG9yPHZlY3RvcjxpbnQ+ID4gYShuLCB2ZWN0b3I8aW50PihtKSk7CiAgICAgICAgdmVjdG9yPGludD4gc3VtYyhuKTsKICAgICAgICB2ZWN0b3I8aW50PiBzdW1yKG0pOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgbTsgaisrKXsKICAgICAgICAgICAgICAgIGNpbiA+PiBhW2ldW2pdOwogICAgICAgICAgICAgICAgc3VtY1tpXSArPSBhW2ldW2pdOwogICAgICAgICAgICAgICAgc3VtcltqXSArPSBhW2ldW2pdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGludCBpID0gMCwgaiA9IDA7CiAgICAgICAgZm9yKGludCB4ID0gMDsgeCA8IHMuc2l6ZSgpOyB4KyspewogICAgICAgICAgICBpZihzW3hdID09ICdEJyl7CiAgICAgICAgICAgICAgICBhW2ldW2pdID0gLSBzdW1jW2ldOwogICAgICAgICAgICAgICAgc3VtY1tpXSArPSBhW2ldW2pdOwogICAgICAgICAgICAgICAgc3VtcltqXSArPSBhW2ldW2pdOwogICAgICAgICAgICAgICAgaSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKHNbeF0gPT0gJ1InKXsKICAgICAgICAgICAgICAgIGFbaV1bal0gPSAtIHN1bXJbal07CiAgICAgICAgICAgICAgICBzdW1jW2ldICs9IGFbaV1bal07CiAgICAgICAgICAgICAgICBzdW1yW2pdICs9IGFbaV1bal07CiAgICAgICAgICAgICAgICBqKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgYVtpXVtqXSA9IC1zdW1yW2pdOwogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG07IGorKyl7CiAgICAgICAgICAgICAgICBjb3V0IDw8IGFbaV1bal0gPDwgIiAiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvdXQgPDwgZW5kbDsKICAgICAgICB9CiAgICB9Cn0=
NAozIDMKRFJSRAowIDIgMwowIDAgMAozIDEgMAo0IDUKRFJSUlJERAowIDEgMCAyIDMKMCAwIDAgMCAwCi0xIDAgLTMgLTMgMAowIDAgMCAtMSAwCjIgMwpSUkQKMCAwIDAKMCAxIDAKNSA1CkRERERSUlJSCjAgMjUgMiA5IDExCjAgNiAxMyAyMCAyMgowIDE3IDI0IDEgOAowIDMgMTAgMTIgMTkKMCAwIDAgMCAwCiA=
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