#include #include #include using namespace std; int table[101][101], rows, cols; void delCell(istream & cin) { int r, c; cin >> r; cin.get(); cin >> c; if(r > rows || c > cols) return; else table[r][c] = INT_MIN; } void delRow(istream & cin) { int row; cin >> row; if(row > rows) return; else { for(int r = row + 1; r <= rows; r++) { for(int c = 1; c <= cols; c++) table[r-1][c] = table[r][c]; } rows--; } } void delCol(istream & cin) { int col; cin >> col; if(col > cols) return; else { for(int c = col + 1; c <= cols; c++) { for(int r = 1; r <= rows; r++) table[r][c-1] = table[r][c]; } cols--; } } void del(string ctype, istream & cin) { if(ctype == "cell") delCell(cin); else if(ctype == "row") delRow(cin); else if(ctype == "col") delCol(cin); } void addCell(istream & cin) { int r1, r2, c1, c2; cin >> r1; cin.get(); cin >> c1 >> r2; cin.get(); cin >> c2; if(r1 > rows || c1 > cols || r2 > rows || c2 > cols) return; else { if(table[r1][c1] == INT_MIN) table[r1][c1] = table[r2][c2]; else if(table[r2][c2] != INT_MIN) table[r1][c1] += table[r2][c2]; } } void addRow(istream & cin) { int r1, r2; cin >> r1 >> r2; if(r1 > rows || r2 > rows) return; else { for(int c = 1; c <= cols; c++) { if(table[r1][c] == INT_MIN) table[r1][c] = table[r2][c]; else if(table[r2][c] != INT_MIN) table[r1][c] += table[r2][c]; } } } void addCol(istream & cin) { int c1, c2; cin >> c1 >> c2; if(c1 > cols || c2 > cols) return; else { for(int r = 1; r <= rows; r++) { if(table[r][c1] == INT_MIN) table[r][c1] = table[r][c2]; else if(table[r][c2] != INT_MIN) table[r][c1] += table[r][c2]; } } } void add(string ctype, istream & cin) { if(ctype == "cell") addCell(cin); else if(ctype == "row") addRow(cin); else if(ctype == "col") addCol(cin); } void subCell(istream & cin) { int r1, r2, c1, c2; cin >> r1; cin.get(); cin >> c1 >> r2; cin.get(); cin >> c2; if(r1 > rows || c1 > cols || r2 > rows || c2 > cols) return; else { if(table[r1][c1] == INT_MIN) table[r1][c1] = table[r2][c2]; else if(table[r2][c2] != INT_MIN) table[r1][c1] -= table[r2][c2]; } } void subRow(istream & cin) { int r1, r2; cin >> r1 >> r2; if(r1 > rows || r2 > rows) return; else { for(int c = 1; c <= cols; c++) { if(table[r1][c] == INT_MIN) table[r1][c] = table[r2][c]; else if(table[r2][c] != INT_MIN) table[r1][c] -= table[r2][c]; } } } void subCol(istream & cin) { int c1, c2; cin >> c1 >> c2; if(c1 > cols || c2 > cols) return; else { for(int r = 1; r <= rows; r++) { if(table[r][c1] == INT_MIN) table[r][c1] = table[r][c2]; else if(table[r][c2] != INT_MIN) table[r][c1] -= table[r][c2]; } } } void sub(string ctype, istream & cin) { if(ctype == "cell") subCell(cin); else if(ctype == "row") subRow(cin); else if(ctype == "col") subCol(cin); } void modify(istream & cin) { int r, c, value; cin >> r; cin.get(); cin >> c >> value; if(r > rows || c > cols) return; table[r][c] = value; } void print(ostream & cout) { if(!rows || !cols) { cout << "Empty" << endl; return; } for(int r = 1; r <= rows; r++) { for(int c = 1; c <= cols; c++) { if(c != 1) cout << "\t"; if(table[r][c] == INT_MIN) cout << "e"; else cout << table[r][c]; } cout << endl; } } int main() { int first = 1; while(cin >> rows >> cols) { if(!rows && !cols) break; if(!first) cout << endl; first = 0; for(int r = 1; r <= rows; r++) { for(int c = 1; c <= cols; c++) { string s; cin >> s; if(s == "e") table[r][c] = INT_MIN; else table[r][c] = atoi(s.c_str()); } } int N; string command, ctype; cin >> N; for(int i = 0; i < N; i++) { cin >> command >> ctype; if(command == "del") del(ctype, cin); else if(command == "modify") modify(cin); else if(command == "add") add(ctype, cin); else if(command == "sub") sub(ctype, cin); } print(cout); } return 0; }