#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
#include <functional>
using namespace std;


const int MAX_V = 500;
using Capacity = int;
using Cost = int;
const auto inf = numeric_limits<Capacity>::max() / 8;

struct Edge {
	int dst;
	Capacity cap, cap_orig;
	Cost cost;
	int revEdge; bool isRev;
	Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
		:dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {
	}
};

struct PrimalDual {
	int n;
	vector<vector<Edge> > g;
	Cost h[MAX_V], dist[MAX_V];
	int prevv[MAX_V], preve[MAX_V];
	PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(int src, int dst, Capacity cap, Cost cost) { // テヲツ慊嘉・ツ青妥ィツセツコ
		g[src].emplace_back(dst, cap, cost, g[dst].size(), false);
		g[dst].emplace_back(src, 0, -cost, g[src].size() - 1, true);
	}
	Cost solve(int s, int t, int f) {
		Cost res = 0;
		for(int i = 0; i < n; i++) {
			h[i] = 0;
		}
		while(f > 0) {
			typedef pair<Cost, int> pcv;
			priority_queue<pcv, vector<pcv>, greater<pcv> > q;
			for(int i = 0; i < n; i++) {
				dist[i] = inf;
			}
			dist[s] = 0;
			q.emplace(pcv(0, s));
			while(q.size()) {
				pcv p = q.top(); q.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i = 0; i < g[v].size(); i++) {
					Edge &e = g[v][i];
					if(e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
						dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
						prevv[e.dst] = v;
						preve[e.dst] = i;
						q.emplace(pcv(dist[e.dst], e.dst));
					}
				}
			}
			if(dist[t] == inf) {
				return -1;
			}
			for(int v = 0; v < n; v++) {
				h[v] += dist[v];
			}
			// s-t テゥツ鳴禿ヲツ慊?ァツ淞ュティツキツッテ」ツ?ォテヲツイツソテ」ツ?」テ」ツ?ヲテァツ崢ョテ、ツクツ?ヲツ敖ッテヲツオツ?」ツ??
			int d = f;
			for(int v = t; v != s; v = prevv[v]) {
				d = min(d, g[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.revEdge].cap += d;
			}
		}
		return res;
	}
	// テヲツオツ?」ツつ古」ツ?淌」ツδ陛」ツδュテ」ツδシ=テ・ツ?ε」ツ??」ツ?ョテ・ツョツケテゥツ??テァツ渉セテ・ツ慊ィテ」ツ?ョテ・ツョツケテゥツ?湘」ツつ津ィツ。ツィテァツ、ツコ
	void view() {
		for(int i = 0; i < g.size(); i++) {
			for(int j = 0; j < g[i].size(); j++) {
				if(!g[i][j].isRev) {
					Edge& e = g[i][j];
					printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
				}
			}
		}
	}
};

int n;
int W[100][100];
int E[100][100];
char F[100][100];
char R[100][100];

struct Command {
	int i, j;
	string s;
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(cin >> n) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cin >> W[i][j];
			}
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cin >> E[i][j];
			}
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cin >> F[i][j];
			}
		}

		PrimalDual pd(2 * n + 2);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				int sum = 0;
				if(F[i][j] == '.') sum += W[i][j];
				for(int k = 0; k < n; k++) {
					if(j == k) continue;
					if(F[i][k] == 'o') sum += E[i][k];
				}
				pd.add_edge(i, n + j, 1, sum);
			}
		}
		for(int i = 0; i < n; i++) {
			pd.add_edge(2 * n, i, 1, 0);
			pd.add_edge(n + i, 2 * n + 1, 1, 0);
		}

		int res = pd.solve(2 * n, 2 * n + 1, n);
		cout << res << endl;
		//pd.view();
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				R[i][j] = '.';
			}
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < pd.g[i].size(); j++) {
				if(!pd.g[i][j].isRev) {
					Edge& e = pd.g[i][j];
					if(e.cap_orig - e.cap == 1) {
						R[i][e.dst - n] = 'o';
					}
				}
			}
		}
		/*for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
			cout << R[i][j];
			}
			cout << endl;
			}*/

		vector<Command> v;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(F[i][j] != R[i][j]) {
					if(F[i][j] == '.') v.push_back(Command{ i + 1, j + 1, "write" });
					else v.push_back(Command{ i + 1, j + 1, "erase" });
				}
			}
		}

		cout << v.size() << endl;
		for(Command c : v) {
			cout << c.i << " " << c.j << " " << c.s << endl;
		}
	}
}

Measured memory_bytes: 3872