#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

typedef pair<int, int> P;

class edge {
public:
	bool is_rev;
	int to, cap, cost, rev;
	edge(int t, int ca, int co, int r, bool i):to(t), cap(ca), cost(co), rev(r), is_rev(i){};
};

struct operation {
	int x, y;
	string name;
	operation(int x, int y, string n):x(x), y(y), name(n){}
};

ostream& operator<<(ostream& os, const operation& o) {
	os << o.x << " " << o.y << " " << o.name;
	return os;
}

vector<vector<edge> > G;

void init(int n) {
	G.clear();
	G.resize(n);
}

void add_edge(int from, int to, int cap, int cost) {
	G[from].push_back(edge(to, cap, cost, G[to].size(), true));
	G[to].push_back(edge(from, 0, -cost, G[from].size() - 1, false));
}

int min_cost_flow(int s, int t, int f) {
	int n = G.size();
	int res = 0;
	vector<int> h(n, 0), prevv(n), preve(n);
	while(f > 0) {
		priority_queue<P, vector<P>, greater<P> > que;
		vector<int> dist(n, INT_MAX);
		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;

			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 + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}

		if(dist[t] == INT_MAX)
			return -1;

		for(int v = 0; v < n; ++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 += 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;
}


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

	int n;
	cin >> n;

	vector<vector<int> > w(n, vector<int>(n)), e(n, vector<int>(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];

	vector<string> board(n);
	for(int i = 0; i < n; ++i)
		cin >> board[i];

	init(n + n + 2);
	const int from = n + n, to = n + n + 1;
	for(int i = 0; i < n; ++i) {
		add_edge(from, i, 1, 0);
		add_edge(n + i, to, 1, 0);
	}

	for(int i = 0; i < n; ++i) {
		int sum = 0;
		for(int j = 0; j < n; ++j)
			if(board[i][j] == 'o')
				sum += e[i][j];

		for(int j = 0; j < n; ++j) {
			const int cost = sum + (board[i][j] == 'o' ? -e[i][j] : w[i][j]);
			add_edge(i, j + n, 1, cost);
		}
	}

	cout << min_cost_flow(from, to, n) << endl;

	vector<operation> ans;
	for(int i = 0; i < n; ++i) {
		int pos = -1;
		for(int j = 0; j < (int)G[i].size(); ++j) {
			if(G[i][j].cap == 0) {
				pos = G[i][j].to - n;
				break;
			}
		}

		if(board[i][pos] == '.')
			ans.push_back(operation(i + 1, pos + 1, "write"));

		for(int j  = 0; j < n; ++j)
			if(j != pos && board[i][j] == 'o')
				ans.push_back(operation(i + 1, j + 1, "erase"));
	}

	cout << ans.size() << endl;
	for(int i = 0; i < (int)ans.size(); ++i)
		cout << ans[i] << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2004