/* AUTHOR: TUAN ANH - BUI */
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class X, class Y>
bool minimize(X &x, const Y &y) {
if (x > y) return x = y, true;
return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
if (x < y) return x = y, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "gen"
/*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN TST26 */
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 27092008;
const ll INF = (ll)1e18 + 27092008;
const int N = 1500 + 5;
int limBoard, val[N][N];
ll delta[N][N], f[N][N], sum;
/*
delta(i, j) = f(i, j) - f(i + 1, j - 1)
delta(i, j) > 0 means f(i, j) is better than f(i + 1, j - 1) for f(i + 1, j)
*/
void init(void) {
cin >> limBoard;
FOR(i, 1, limBoard) FOR(j, 1, limBoard) {
cin >> val[i][j];
f[i][j] = max(f[i - 1][j], f[i][j - 1]) + val[i][j];
sum += f[i][j];
}
}
void process(void) {
FOR(i, 1, limBoard) FOR(j, 1, limBoard) delta[i][j] = f[i][j] - f[i + 1][j - 1];
cout << sum << '\n';
REP(query, limBoard) {
char type;
int row, col;
cin >> type >> row >> col;
if (type == 'U') {
int Lrow, Rrow, Lcol, Rcol;
Lrow = Rrow = row;
Lcol = Rcol = col;
while(Lcol <= Rcol) {
sum += Rcol - Lcol + 1;
delta[Lrow][Lcol]++;
delta[Rrow - 1][Rcol + 1]--;
if (Lrow == limBoard && Lcol == limBoard) break;
if (Lrow < limBoard && (Lcol == 1 || delta[Lrow][Lcol] > 0))
Lrow++;
else
Lcol++;
if (Rcol < limBoard && (Rrow == 1 || delta[Rrow - 1][Rcol + 1] < 0))
Rcol++;
else
Rrow++;
}
} else {
int Lrow, Rrow, Lcol, Rcol;
Lrow = Rrow = row;
Lcol = Rcol = col;
while(Lcol <= Rcol) {
sum -= Rcol - Lcol + 1;
delta[Lrow][Lcol]--;
delta[Rrow - 1][Rcol + 1]++;
if (Lrow == limBoard && Lcol == limBoard) break;
if (Lrow < limBoard && (Lcol == 1 || delta[Lrow][Lcol] >= 0))
Lrow++;
else
Lcol++;
if (Rcol < limBoard && (Rrow == 1 || delta[Rrow - 1][Rcol + 1] <= 0))
Rcol++;
else
Rrow++;
}
}
cout << sum << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}