#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <functional>
using namespace std;

static const int INF = 1e9;
struct MinCostFlow {
	struct E {
		//to,??????,?????????,?????????index
		int to, cap, cost, rev;
		E(int t, int ca, int co, int r) {
			to = t;
			cap = ca;
			cost = co;
			rev = r;
		}
	};

	//?????§????????°
	int V;
	vector<vector<E>>G;
	MinCostFlow(int v) {
		V = v;
		G.resize(V);
	}

	//?????????
	inline void add_edge(int from, int to, int cap, int cost) {
		if (from == to)return;
		E e = E(to, cap, cost, G[to].size());
		E ee = E(from, 0, -cost, G[from].size());
		G[from].push_back(e);
		G[to].push_back(ee);
	}

	//?????????????????¢??¨??????
	//?????????,????°??????????
	vector<int>dist, mindist;
	//??????????????¨
	vector<int>pre_v, pre_i;

	//?§????????????????????????§???????°??????????
	void dijkstra(int s) {
		priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > que;
		dist.assign(V, INF);
		dist[s] = 0;
		que.push(pair<int, int>(0, s));
		while (!que.empty()) {
			pair<int, int> p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first)continue;

			for (int i = 0; i < G[v].size(); i++) {
				E &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + mindist[v] - mindist[e.to]) {
					dist[e.to] = dist[v] + e.cost + mindist[v] - mindist[e.to];
					pre_v[e.to] = v;
					pre_i[e.to] = i;
					que.push(pair<int, int>(dist[e.to], e.to));
				}
			}
		}
	}

	//????°??????¨?????????
	int min_cost_flow(int s, int t, int flow) {
		int cost = 0;
		mindist.resize(V);
		pre_v.resize(V);
		pre_i.resize(V);

		//????????????????????????????????§
		while (flow > 0) {
			dijkstra(s);
			//????????????????????£??????
			if (dist[t] == INF)return -1;

			//????°???????????????´??°
			for (int v = 0; v < V; v++)mindist[v] += dist[v];

			//????°???????????????????????????§???
			int f = flow;
			for (int v = t; v != s; v = pre_v[v]) {
				f = min(f, G[pre_v[v]][pre_i[v]].cap);
			}
			flow -= f;

			//?????¨?????´??°
			cost += f * mindist[t];

			//???????????´??°
			for (int v = t; v != s; v = pre_v[v]) {
				E& e = G[pre_v[v]][pre_i[v]];
				E& ee = G[v][e.rev];
				e.cap -= f;
				ee.cap += f;
			}
		}

		return cost;
	}
};

int main()
{
	int n; cin >> n;
	vector<vector<int>>W(n), E(n);
	vector<vector<int>>F(n);
	vector<vector<int>>we(n);
	int C = 0;
	for (int i = 0; i < n; i++) {
		W[i].resize(n);
		for (int j = 0; j < n; j++) {
			cin >> W[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		E[i].resize(n);
		for (int j = 0; j < n; j++) {
			cin >> E[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		F[i].resize(n);
		we[i].resize(n);
		for (int j = 0; j < n; j++) {
			char c; cin >> c;
			if (c == 'o') {
				C += E[i][j];
				F[i][j] = -E[i][j];
				we[i][j]--;
			}
			else F[i][j] = W[i][j];
		}
	}

	MinCostFlow mcf(2*n+2);

	for (int i = 0; i < n; i++) {
		mcf.add_edge(0,i+1,1,0);
		for (int j = 0; j < n; j++) {
			mcf.add_edge(i + 1, n + j + 1, 1, F[i][j]);
		}
		mcf.add_edge(n + i + 1, 2 * n + 1, 1, 0);
	}

	int ans = mcf.min_cost_flow(0, 2 * n + 1, n);

	cout << C+ans << endl;

	for (int i = 0; i < n; i++) {
		for (int j = 1; j < n+1; j++) {
			if (mcf.G[i + 1][j].cap == 0) {
				we[i][mcf.G[i + 1][j].to - n - 1]++;
			}
		}
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (we[i][j] != 0)cnt++;
		}
	}
	cout << cnt << endl;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (we[i][j] == 1)cout << i+1 << " " << j+1 << " " << "write" << endl;
			else if(we[i][j]==-1)cout << i+1 << " " << j+1 << " " << "erase" << endl;
		}
	}

    return 0;
}

Measured memory_bytes: 3488