#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define fi(i,l,n) for(int i=l; i<n; i++)
#define fd(i,n,l) for(int i=n; i>=l; i--)
#define gets(s) string s; cin>>s;
#define getv(v,n) vector<ll> v(n+1); fi(i,1,n+1) cin>>v[i];
#define all1(v) v.begin() + 1, v.end()
#define all(v) v.begin(), v.end()
#define seev(v,n) fr(i,1,n+1) {cout<<v[i]<<' ';} cout<<endl;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vp vector<pair<ll,ll>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define pb push_back
#define mp make_pair
#define mse multiset<ll>
#define se set<ll>
#define ma map<ll,ll>
#define getmat(v,n,m) vvl v(n+1,vl(m+1)); fi(i,1,n+1) {fi (j,1,m+1) cin>>v[i][j];}
#define seemat(mat) fi(i,1,n+1) {fi (j,1,m+1) cout<<v[i][j]<<' '; cout<<endl;}
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
using namespace std;
using namespace __gnu_pbds;
// Define ordered multiset with long long
typedef tree<long long, long long, less<long>, rb_tree_tag, tree_order_statistics_node_update> ordered_multimap;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
vl sieve;
void SieveOfEratosthenes(int n)
{
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
vl prime(n+1,true);
for (int p = 2; p * p <= n; p++) {
// If prime[p] is not changed, then it is a prime
if (prime[p] == true) {
// Update all multiples of p greater than or
// equal to the square of it numbers which are
// multiple of p and are less than p^2 are
// already been marked.
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
// Print all prime numbers
for (int p = 2; p <= n; p++)
if (prime[p])
sieve.push_back(p);
}
class DisjointSet{
private:
vector<int> parent;
public:
DisjointSet(int n){
parent.resize(n+1,-1);
}
int findParent(int x){
if(parent[x] < 0) return x;
return parent[x] = findParent(parent[x]);
}
void Union(int x, int z){
int px = findParent(x);
int pz = findParent(z);
if(px == pz) return;
if(parent[px] < parent[pz]){
parent[px] += parent[pz];
parent[pz] = px;
}
else {
parent[pz] += parent[px];
parent[px] = pz;
}
}
int getSize(int x){
int px = findParent(x);
return ((-1)*parent[px]);
}
};
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b){
return (a.second < b.second);
}
ll gcd(ll a, ll b){
if (b == 0) return a;
return gcd(b,a%b);
}
ll pwr(ll a, ll b, ll mod = 0){
ll result = 1;
if(mod == 0){
while(b){
if(b & 1) result *= a;
a *= a;
b = b >> 1;
}
}
else {
while(b){
if(b & 1){
result *= a;
result = result % mod;
}
a *= a;
a = a % mod;
b = b >> 1;
}
}
return result;
}
ll modularinverse(ll a,ll p)// p is prime
{
return pwr(a,p-2,p);
}
void solve(ll tc){
int n,m;
cin>>n>>m;
string s;
cin>>s;
ll a[n][m];
fi(i,0,n) fi(j,0,m) cin>>a[i][j];
int r=0,c=0;
int step = 0;
a[r][c] = 0;
ll sum=0;
if(s[0] == 'D'){
fi(col,0,m) sum+=a[0][col];
}
else{
fi(row,0,n) sum+=a[row][0];
}
a[r][c] = -1*sum;
sum=0;
while(step<n+m-1){
ll curr=0;
step++;
if(s[step-1] == 'D'){
r++;
}
else c++;
if(s[step] == 'D'){
fi(col,0,m){
if(col == c) continue;
curr+=a[r][col];
}
a[r][c] = sum - curr;
}
else{
fi(row,0,n){
if(row == r) continue;
curr+=a[row][c];
}
a[r][c] = sum - curr;
}
}
// ll curr = 0;
fi(i,0,n){
fi(j,0,m) cout<<a[i][j]<<' ';
cout<<endl;
}
// fi(i,0,n){
// fi(j,0,m) curr+=a[i][j];
// if(curr!= 0 ) NO
// curr = 0;
// }
// fi(j,0,m){
// fi(i,0,n) curr += a[i][j];
// if(curr != 0) NO
// curr = 0;
// }
// YES
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
cin>>t;
ll t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wXSA9PSB0cnVlKSB7CiAgICAgICAgICAgIC8vIFVwZGF0ZSBhbGwgbXVsdGlwbGVzIG9mIHAgZ3JlYXRlciB0aGFuIG9yCiAgICAgICAgICAgIC8vIGVxdWFsIHRvIHRoZSBzcXVhcmUgb2YgaXQgbnVtYmVycyB3aGljaCBhcmUKICAgICAgICAgICAgLy8gbXVsdGlwbGUgb2YgcCBhbmQgYXJlIGxlc3MgdGhhbiBwXjIgYXJlCiAgICAgICAgICAgIC8vIGFscmVhZHkgYmVlbiBtYXJrZWQuCiAgICAgICAgICAgIGZvciAoaW50IGkgPSBwICogcDsgaSA8PSBuOyBpICs9IHApCiAgICAgICAgICAgICAgICBwcmltZVtpXSA9IGZhbHNlOwogICAgICAgIH0KICAgIH0KIAogICAgLy8gUHJpbnQgYWxsIHByaW1lIG51bWJlcnMKICAgIGZvciAoaW50IHAgPSAyOyBwIDw9IG47IHArKykKICAgICAgICBpZiAocHJpbWVbcF0pCiAgICAgICAgICAgIHNpZXZlLnB1c2hfYmFjayhwKTsKfQoKY2xhc3MgRGlzam9pbnRTZXR7CiAgICBwcml2YXRlOgogICAgdmVjdG9yPGludD4gcGFyZW50OwoKICAgIHB1YmxpYzoKICAgIERpc2pvaW50U2V0KGludCBuKXsKICAgICAgICBwYXJlbnQucmVzaXplKG4rMSwtMSk7CiAgICB9CgogICAgaW50IGZpbmRQYXJlbnQoaW50IHgpewogICAgICAgIGlmKHBhcmVudFt4XSA8IDApIHJldHVybiB4OwogICAgICAgIHJldHVybiBwYXJlbnRbeF0gPSBmaW5kUGFyZW50KHBhcmVudFt4XSk7CiAgICB9CgogICAgdm9pZCBVbmlvbihpbnQgeCwgaW50IHopewogICAgICAgIGludCBweCA9IGZpbmRQYXJlbnQoeCk7CiAgICAgICAgaW50IHB6ID0gZmluZFBhcmVudCh6KTsKICAgICAgICAKICAgICAgICBpZihweCA9PSBweikgICAgcmV0dXJuOwogICAgICAgIAogICAgICAgIGlmKHBhcmVudFtweF0gPCBwYXJlbnRbcHpdKXsKICAgICAgICAgICAgcGFyZW50W3B4XSArPSBwYXJlbnRbcHpdOwogICAgICAgICAgICBwYXJlbnRbcHpdID0gcHg7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICBwYXJlbnRbcHpdICs9IHBhcmVudFtweF07CiAgICAgICAgICAgIHBhcmVudFtweF0gPSBwejsKICAgICAgICB9CiAgICAgICAgCiAgICB9CgogICAgaW50IGdldFNpemUoaW50IHgpewogICAgICAgIGludCBweCA9IGZpbmRQYXJlbnQoeCk7CiAgICAgICAgcmV0dXJuICgoLTEpKnBhcmVudFtweF0pOwogICAgfQp9OwoKYm9vbCBzb3J0YnlzZWMoY29uc3QgcGFpcjxsbCwgbGw+JiBhLCBjb25zdCBwYWlyPGxsLCBsbD4mIGIpewogICAgcmV0dXJuIChhLnNlY29uZCA8IGIuc2Vjb25kKTsKfQoKCmxsIGdjZChsbCBhLCBsbCBiKXsKICAgIGlmIChiID09IDApIHJldHVybiBhOwogICAgcmV0dXJuIGdjZChiLGElYik7Cn0KCgpsbCBwd3IobGwgYSwgbGwgYiwgbGwgbW9kID0gMCl7CiAgICBsbCByZXN1bHQgPSAxOwogICAgaWYobW9kID09IDApewogICAgICAgIHdoaWxlKGIpewogICAgICAgICAgICBpZihiICYgMSkgcmVzdWx0ICo9IGE7CiAgICAgICAgICAgIGEgKj0gYTsKICAgICAgICAgICAgYiA9IGIgPj4gMTsKICAgICAgICB9CiAgICB9CiAgICBlbHNlIHsKICAgICAgICB3aGlsZShiKXsKICAgICAgICAgICAgaWYoYiAmIDEpewogICAgICAgICAgICAgICAgcmVzdWx0ICo9IGE7CiAgICAgICAgICAgICAgICByZXN1bHQgID0gcmVzdWx0ICUgbW9kOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGEgKj0gYTsKICAgICAgICAgICAgYSA9IGEgJSBtb2Q7CiAgICAgICAgICAgIGIgPSBiID4+IDE7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJlc3VsdDsKfQoKCmxsIG1vZHVsYXJpbnZlcnNlKGxsIGEsbGwgcCkvLyBwIGlzIHByaW1lCnsKICAgIHJldHVybiBwd3IoYSxwLTIscCk7Cn0KCnZvaWQgc29sdmUobGwgdGMpewogICAgaW50IG4sbTsKICAgIGNpbj4+bj4+bTsKCiAgICBzdHJpbmcgczsKICAgIGNpbj4+czsKCiAgICBsbCBhW25dW21dOwoKICAgIGZpKGksMCxuKSBmaShqLDAsbSkgY2luPj5hW2ldW2pdOwoKICAgIGludCByPTAsYz0wOwogICAgaW50IHN0ZXAgPSAwOwogICAgYVtyXVtjXSA9IDA7CgogICAgbGwgc3VtPTA7CgogICAgaWYoc1swXSA9PSAnRCcpewogICAgICAgIGZpKGNvbCwwLG0pIHN1bSs9YVswXVtjb2xdOwogICAgfQogICAgZWxzZXsKICAgICAgICBmaShyb3csMCxuKSBzdW0rPWFbcm93XVswXTsKICAgIH0KCiAgICBhW3JdW2NdID0gLTEqc3VtOwogICAgc3VtPTA7CgoKCiAgICB3aGlsZShzdGVwPG4rbS0xKXsKICAgICAgICBsbCBjdXJyPTA7CiAgICAgICAgc3RlcCsrOwoKICAgICAgICBpZihzW3N0ZXAtMV0gPT0gJ0QnKXsKICAgICAgICAgICAgcisrOwogICAgICAgIH0KICAgICAgICBlbHNlIGMrKzsKCiAgICAgICAgaWYoc1tzdGVwXSA9PSAnRCcpewogICAgICAgICAgICBmaShjb2wsMCxtKXsKICAgICAgICAgICAgICAgIGlmKGNvbCA9PSBjKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIGN1cnIrPWFbcl1bY29sXTsKICAgICAgICAgICAgfSAKCiAgICAgICAgICAgIGFbcl1bY10gPSBzdW0gLSBjdXJyOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICBmaShyb3csMCxuKXsKICAgICAgICAgICAgICAgIGlmKHJvdyA9PSByKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIGN1cnIrPWFbcm93XVtjXTsKICAgICAgICAgICAgfSAKCiAgICAgICAgICAgIGFbcl1bY10gPSBzdW0gLSBjdXJyOwogICAgICAgIH0KCiAgICB9IAoKCiAgICAvLyBsbCBjdXJyID0gMDsKCiAgICBmaShpLDAsbil7CiAgICAgICAgZmkoaiwwLG0pIGNvdXQ8PGFbaV1bal08PCcgJzsKICAgICAgICBjb3V0PDxlbmRsOwogICAgfQoKICAgIC8vIGZpKGksMCxuKXsKICAgIC8vICAgICBmaShqLDAsbSkgY3Vycis9YVtpXVtqXTsKICAgIC8vICAgICBpZihjdXJyIT0gMCApIE5PCiAgICAvLyAgICAgY3VyciA9IDA7CiAgICAvLyB9CgogICAgLy8gZmkoaiwwLG0pewogICAgLy8gICAgIGZpKGksMCxuKSBjdXJyICs9IGFbaV1bal07CiAgICAvLyAgICAgaWYoY3VyciAhPSAwKSBOTwogICAgLy8gICAgIGN1cnIgPSAwOwogICAgLy8gfQogICAgLy8gWUVTCn0KCmludCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBjb3V0LnRpZShOVUxMKTsKICAgIAogICAgaW50IHQ9MTsKICAgIGNpbj4+dDsKICAgIGxsIHRjPTA7CiAgICB3aGlsZSh0LS0pewogICAgICAgIHRjKys7CiAgICAgICAgc29sdmUodGMpOwogICAgfQogICAgCiAgICByZXR1cm4gMDsKfQ==