#include "bits/stdc++.h"
using namespace std;
using ld = long double;
const ld eps = 1e-9;

typedef long long  Weight;
struct Edge {
	int src, dest;
	int cap, rev;
	Weight weight;
	bool operator < (const Edge &rhs) const { return weight > rhs.weight; }
};

const int V = 4000;
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
Weight h[V];                //テ」ツδ敕」ツδ?」ツδウテ」ツつキテ」ツδ」テ」ツδォ
Weight dist[V];             //テヲツ慊?ァツ淞ュティツキツ敕ゥツ崢「
int prevv[V], preve[V];  //テァツ崢エテ・ツ可催」ツ?ョティツセツコテ」ツ?ィテゥツ?づァツつケ

void add_edge(Graph &g, int src, int dest, int cap, Weight weight) {
	g[src].push_back(Edge{ src, dest, cap, (int)g[dest].size(), weight });
	g[dest].push_back(Edge{ dest, src, 0, (int)g[src].size() - 1, -weight });
}
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const Weight INF = 2147483647;
Weight min_cost_flow(Graph &g, int s, int t, int f) {
	Weight res = 0;
	memset(h, 0, sizeof(h));
	typedef pair<Weight, int> P;
	while (f > 0) {
		priority_queue<P, vector<P>, greater<P> > que;
		fill(dist, dist + V, INF);
		dist[s] = 0;
		que.push(P(0, s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			REP(i, g[v].size()) {
				Edge &e = g[v][i];
				if (e.cap > 0 && dist[e.dest] > dist[v] + e.weight + h[v] - h[e.dest]) {
					dist[e.dest] = dist[v] + e.weight + h[v] - h[e.dest];
					prevv[e.dest] = v;
					preve[e.dest] = i;
					que.push(P(dist[e.dest], e.dest));
				}
			}
		}
		if (dist[t] == INF) return -1;
		REP(v, V) h[v] =h[v]+ dist[v];

		int d = f;
		for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap);
		f -= d;
		res = 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.rev].cap += d;
		}
	}
	return res;
}

struct ope {
	int x;
	int y;
	bool write;
};

int main() {
	int N; cin >> N;
	vector<vector<int>>ws(N, vector<int>(N)), ds(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> ws[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> ds[i][j];
		}
	}
	vector<vector<int>>field(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		string st; cin >> st;
		for (int j = 0; j < N; ++j) {
			field[i][j] = st[j] == 'o';
		}
	}
	const int start = 0;
	const int l = start+1;
	const int u = l + N;
	const int goal = u + N;
	Graph g(goal + 1);
	for (int i = 0; i <N; ++i) {
		add_edge(g, start, l + i, 1, 0);
	}

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			int cost = 0;
			for (int k = 0; k < N; ++k) {
				if (j == k) {
					if (!field[i][k])cost += ws[i][k];
				}
				else {
					if (field[i][k])cost += ds[i][k];
				}
			}
			add_edge(g, l + i, u + j, 1, cost);
		}
	}
	for (int i = 0; i < N; ++i) {
		add_edge(g, u + i, goal, 1, 0);
	}
	vector<ope>opes;
	int ans = min_cost_flow(g, start, goal,N);
	for (int i = 0; i < N; ++i) {
		for (auto e : g[l + i]) {
			if (e.dest) {
				int x = e.dest - u;

				//テ「ツ猟?
				if (e.cap == 0) {
					if (!field[i][x]) {
						opes.push_back(ope{ x,i,true });
					}
				}
				else {
					if (field[i][x]) {
						opes.push_back(ope{ x,i,false });
					}
				}
			}
		}
	}
	cout << ans << endl;
	cout << opes.size() << endl;
	for (auto o : opes) {
		cout << o.y + 1 << " " << o.x+ 1 << " ";
		if (o.write)cout << "write" << endl;
		else cout << "erase" << endl;
	}
	return 0;
}

Measured memory_bytes: 3836