#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight capacity, cost;
  int rev;
  Edge(int src, int dst, Weight capacity, Weight cost) :
    src(src), dst(dst), capacity(capacity), cost(cost) { }
  Edge(int src, int dst, Weight capacity, Weight cost, int rev) :
    src(src), dst(dst), capacity(capacity), cost(cost), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.cost != f.cost ? e.cost > f.cost : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int s, int d, Weight cap, Weight cost) {
  g[s].push_back(Edge(s,d,cap,cost));
  g[d].push_back(Edge(d,s,0,-cost));
}

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])

int ans[100][100];
int W[100][100];
int E[100][100];
string F[100];
int n,N;

int SOURCE() { return n*2; }
int SINK() { return n*2+1; }
int ROW(int i) { return i; }
int COL(int i) {return n+i; }


// Dijkstra
pair<Weight, Weight> minimumCostFlow(const Graph &g, int s, int t) {
  const int n = g.size();
  Matrix capacity(n, Array(n)), cost(n, Array(n)), flow(n, Array(n));
  REP(u,n) FOR(e,g[u]) {
    capacity[e->src][e->dst] += e->capacity;
    cost[e->src][e->dst] += e->cost;
  }
  pair<Weight, Weight> total; // (cost, flow)
  vector<Weight> h(n, INF);
  h[s] = 0;
  // ベルマンフォードでポテンシャルを求めて負辺に対応
  REP(k, n) REP(i, n) FOR(e,g[i]) if (capacity[e->src][e->dst])
    h[e->dst] = min(h[e->dst], h[e->src] + cost[e->src][e->dst]);
  
  for (Weight F = INF; F > 0; ) { // residual flow
    vector<Weight> d(n, INF); d[s] = 0;
    vector<int> p(n, -1);
    priority_queue<Edge> Q;
    for (Q.push(Edge(-2, s, 0, 0)); !Q.empty(); ) {
      Edge e = Q.top(); Q.pop();
      if (p[e.dst] != -1) continue;
      p[e.dst] = e.src;
      FOR(f, g[e.dst]) if (RESIDUE(f->src, f->dst) > 0) {
        if (d[f->dst] > d[f->src] + RCOST(f->src, f->dst)) {
          d[f->dst] = d[f->src] + RCOST(f->src, f->dst);
          Q.push( Edge(f->src, f->dst, 0, d[f->dst]) );
        }
      }
    }
    if (p[t] == -1) break;    
    Weight f = F;
    for (int u = t; u != s; u = p[u])
      f = min(f, RESIDUE(p[u], u));
    for (int u = t; u != s; u = p[u]) {
      total.first += f * cost[p[u]][u];
      flow[p[u]][u] += f; flow[u][p[u]] -= f;
    }
    F -= f;
    total.second += f;
    REP(u, n) if (h[u] != INF) h[u] += d[u]; // ifいらない？
  }
  REP(i,N) REP(j,N) ans[i][j] = flow[ROW(i)][COL(j)];
  return total;
}

int cost[100][100];
int main() {
  cin >> n;
  N = n;
  REP(i,n)REP(j,n)cin>>W[i][j];
  REP(i,n)REP(j,n)cin>>E[i][j];
  REP(i,n) cin >> F[i];
  Graph g(n+n+2);
  REP(i,n) {
    REP(j,n) {
      // cout << i << " " << j << " " << E[i][j] << " " << W[i][j] << endl;
      if (F[i][j] == 'o') {
        REP(k,n) {
          if (k==j) continue;
          cost[i][k] += E[i][j];
        }
      } else {
        cost[i][j] += W[i][j];
      }
    }
  }
  
  REP(i,n) REP(j,n) add_edge(g,ROW(i),COL(j),1,cost[i][j]);

  // REP(i,n) {
  //   REP(j,n) cout << cost[i][j] << " " ;
  //   cout << endl;
  // }
  
  REP(i,n) add_edge(g,SOURCE(),ROW(i),1,0);
  REP(i,n) add_edge(g,COL(i),SINK(),1,0);
  pii res = minimumCostFlow(g,SOURCE(),SINK());
  
  cout << res.first << endl;
  vector<pii> ans2;
  REP(i,n) {
    REP(j,n) {
      if (ans[i][j] ^ (F[i][j]=='o')) {
        ans2.push_back(pii(i,j));
      }
    }
  }
  sort(ALL(ans2));
  cout << ans2.size() << endl;
  FOR(it, ans2) {
    cout << it->first+1 << " " << it->second+1 << " ";
    if(F[it->first][it->second]=='o') cout << "erase";
    else cout << "write";
    cout << endl;
  }
}