#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n, m;
cin >> n >> m;
string s;
cin >> s;
int a[n][m];
ll s1[n], s2[m];
memset(s1, 0, sizeof s1);
memset(s2, 0, sizeof s2);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
s1[i] += a[i][j];
s2[j] += a[i][j];
}
}
int x = 0, y = 0;
for(int i = 0; i < s.size(); i++){
if(s[i] == 'R'){
a[x][y] = -s2[y];
s1[x] += (-s2[y]);
s2[y] = 0;
y++;
}else{
a[x][y] = -s1[x];
s2[y] += (-s1[x]);
s1[x] = 0;
x++;
}
}
a[n - 1][m - 1] = -s1[n - 1];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)cout << a[i][j] <<" ";
cout << "\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for(int i = 1; i <= t; i++){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7Cgp2b2lkIHNvbHZlKCl7CglpbnQgbiwgbTsKCWNpbiA+PiBuID4+IG07CglzdHJpbmcgczsKCWNpbiA+PiBzOwoJCglpbnQgYVtuXVttXTsKCQoJbGwgczFbbl0sIHMyW21dOwoJbWVtc2V0KHMxLCAwLCBzaXplb2YgczEpOwoJbWVtc2V0KHMyLCAwLCBzaXplb2YgczIpOwoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CgkJZm9yKGludCBqID0gMDsgaiA8IG07IGorKyl7CgkJCWNpbiA+PiBhW2ldW2pdOwoJCQlzMVtpXSArPSBhW2ldW2pdOwoJCQlzMltqXSArPSBhW2ldW2pdOwoJCX0KCX0KCWludCB4ID0gMCwgeSA9IDA7Cglmb3IoaW50IGkgPSAwOyBpIDwgcy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