#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct MinimumCostFlow {
	using Flow = int;
	using Cost = int;
	struct Edge {
		int to, rev;
		Flow cap;
		Cost cost;
		Edge() {}
		Edge(int to, int rev, Flow cap, Cost cost) :to(to), rev(rev), cap(cap), cost(cost) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<int> dist;
	vector<int> prevv, preve;
	MinimumCostFlow(int n) :n(n), g(n), dist(n), prevv(n), preve(n) {}
	void addArc(int from, int to, Flow cap, Cost cost) {
		g[from].emplace_back(to, (int)g[to].size(), cap, cost);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost);
	}
	// s??????t????????????f???????°??????¨???
	// ??????????????´?????? -1
	Cost minimumCostFlow(int s, int t, Flow f) {
		Cost total = 0;
		while (f > 0) {
			// Bellman-Ford
			fill(dist.begin(), dist.end(), INF);
			dist[s] = 0;
			bool update = true;
			while (update) {
				update = false;
				for (int v = 0; v < n; v++) {
					if (dist[v] == INF)continue;
					for (int i = 0; i < g[v].size(); i++) {
						Edge &e = g[v][i];
						if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			}
			// ????????\???????????????
			if (dist[t] == INF)
				return -1;
			// ?????????????????£??????????????????
			int d = f;
			for (int v = t; v != s; v = prevv[v])
				d = min(d, g[prevv[v]][preve[v]].cap);
			f -= d;
			total += d*dist[t];
			for (int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.rev].cap += d;
			}
		}
		return total;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<vector<int>> W(n, vector<int>(n));
	rep(i, 0, n) rep(j, 0, n) { cin >> W[i][j]; }
	vector<vector<int>> E(n, vector<int>(n));
	rep(i, 0, n) rep(j, 0, n) { cin >> E[i][j]; }
	int ans = 0;
	MinimumCostFlow mcf(n + n + 2);
	int s = n + n, t = s + 1;
	vector<vector<char>> F(n, vector<char>(n));
	rep(i, 0, n) rep(j, 0, n) { cin >> F[i][j]; }
	rep(i, 0, n)rep(j, 0, n) {
		if (F[i][j] == 'o') {
			ans += E[i][j];
			mcf.addArc(i, n + j, 1, -E[i][j]);
		}
		else {
			mcf.addArc(i, n + j, 1, W[i][j]);
		}
	}
	rep(i, 0, n) {
		mcf.addArc(s, i, 1, 0);
		mcf.addArc(i + n, t, 1, 0);
	}
	ans += mcf.minimumCostFlow(s, t, n);
	cout << ans << endl;
	vector<string> op;
	rep(i, 0, n) {
		for (auto &e : mcf.g[i]) {
			int j = e.to - n;
			if (j >= n)continue;
			if (e.cap == 1 && F[i][j] == 'o') {
				op.emplace_back(to_string(i + 1) + " " + to_string(j + 1) + " erase");
			}
			else if (e.cap == 0 && F[i][j] == '.') {
				op.emplace_back(to_string(i + 1) + " " + to_string(j + 1) + " write");
			}
		}
	}
	cout << op.size() << endl;
	rep(i, 0, op.size()) { cout << op[i] << endl; }
	return 0;
}

Measured memory_bytes: 3788