/* There is a problem with the data of two consecutive questions, Ora. I just got started and thought this question simple. I directly simulated it. amount... */# include <cstdio> # include <cstring> # include <string> # include <iostream> # include <cstdlib> using namespace std; const int maxn = 1001; const int Min =-100000000; int map [maxn] [maxn]; string s; string str [maxn] [maxn]; int n, m; int dfs (int x, int y) {if (map [x] [y]! = Min) return map [x] [y]; map [x] [y] = 0; int len = str [x] [y]. size (); int dx = 0; int dy = 0; for (int I = 0; I <len; I ++) {if (isalpha (str [x] [y] [I]) {dy = dy * 26 + str [x] [y] [I]-'A' + 1 ;} else if (str [x] [y] [I]> = '0' & str [x] [y] [I] <= '9 ') {dx = dx * 10 + str [x] [y] [I]-'0 ';} if (str [x] [y] [I] = '+' | I = len-1) {map [x] [y] + = dfs (dx, dy); dx = 0; dy = 0;} return map [x] [y];} int main () {int T = 0; scanf ("% d ", & T); while (T --) {scanf ("% d", & m, & n); memset (map, 0, sizeof (map )); for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {cin> s; int len = s. size (); if (s [0] = ') {str [I] [j] = s; map [I] [j] = Min ;} else {map [I] [j] = atoi (s. c_str () ;}}for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {if (map [I] [j] = Min) map [I] [j] = dfs (I, j );}} for (int I = 1; I <= n; I ++) {printf ("% d", map [I] [1]); for (int j = 2; j <= m; j ++) {printf ("% d", map [I] [j]);} printf ("\ n ");}} return 0 ;}