#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

struct Edge{
  int to, cap, cost, rev;
  Edge(int to_=0, int cap_ = 0, int cost_ = 0, int rev_ = 0)
	:to(to_), cap(cap_), cost(cost_), rev(rev_){}
};

const int MAX_V = 100*5;
int V;
vector<Edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

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

int min_cost_flow(int s, int t, int f){
  int res = 0;
  while(f > 0){
	fill(dist, dist+V, INF);
	dist[s] = 0;
	bool update = true;
	while(update){
	  update = false;
	  for(int v=0;v<V;++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[v] + e.cost < dist[e.to]){
			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;
	res += 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 res;
}

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


  int N; cin >> N;
  VVI ws(N, VI(N)), es(N, VI(N));
  REP(y,N) REP(x,N) cin >> ws[y][x];
  REP(y,N) REP(x,N) cin >> es[y][x];

  VS vs(N);
  REP(i,N) cin >> vs[i];

  int S = N*2;
  int T = S + 1;
  V = T+1;

  REP(i,N) add_edge(S, i, 1, 0);
  REP(i,N) add_edge(i+N, T, 1, 0);
  
  int bias = 0;
  REP(y,N) REP(x,N){
	if(vs[y][x] == '.'){
	  add_edge(y, N+x, 1, ws[y][x]);
	}
	else{
	  add_edge(y, N+x, 1, -es[y][x]);
	  bias += es[y][x];
	}
  }
  int ans = min_cost_flow(S, T, N) + bias;

  cout << ans << endl;
  vector<pair<PII,string>> qs;
  REP(y,N){
	for(auto&& e: G[y]){
	  int x = e.to - N;
	  if(e.cap == 0 && vs[y][x] == '.'){
		qs.EB(MP(y+1,x+1), "write");
	  }
	  else if(e.cap == 1 && vs[y][x] == 'o'){
		qs.EB(MP(y+1,x+1), "erase");
	  }
	}
  }

  cout << SZ(qs) << endl;
  for(auto&& p: qs){
	cout << p.FF << " " << p.SS << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3664