#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <limits>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

#define MAX_V 210
#define INF 1000000000000000000LL

typedef pair<long long, long long> P;
struct edge{long long to, cap, cost, rev;};
vector<edge> G[MAX_V];
long long h[MAX_V];
long long dist[MAX_V];
long long prevv[MAX_V];
long long preve[MAX_V];

void ae(long long from, long long to, long long cap, long long cost){
  G[from].push_back((edge){to, cap, cost, G[to].size()});
  G[to].push_back((edge){from, 0, -cost, G[from].size() - 1});
}

long long minCostFlow(long long s, long long t, long long f, long long V){
  long long res = 0;
  memset(h,0,sizeof(h));
  while(f > 0){
    priority_queue<P, vector<P>, greater<P> > que;
    for(long long i = 0; i < V; i++){
      dist[i] = INF;
    }
    dist[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      long long v = p.second;
      if(dist[v] < p.first)continue;
      for(long long 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] == INF){
      return -1;
    }
    for(long long v = 0; v < V; v++){
      h[v] += dist[v];
    }
    long long d = f;
    for(long long v = t; v != s; v = prevv[v]){
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for(long long 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;
}

ll dw[110][110];
ll de[110][110];
vector<string> vs;

int main(){
    ll n;
    cin>>n;
    rep(y,0,n){
        rep(x,0,n){
            ll a;
            cin>>a;
            dw[y][x] = a;
        }
    }
    rep(y,0,n){
        rep(x,0,n){
            ll a;
            cin>>a;
            de[y][x] = a;
        }
    }
    rep(i,0,n){
        string s;
        cin>>s;
        vs.pb(s);
    }
    rep(y,0,n){
        rep(x,0,n){
            ll c = 0;
            if(vs[y][x] == '.')c += dw[y][x];
            rep(i,0,n){
                if(i==x)continue;
                if(vs[y][i]=='o')c += de[y][i];
            }
            ae(y,n+x,1,c);
        }
    }
    ll start = 2*n;
    ll end = 2*n+1;
    rep(i,0,n){
        ae(start,i,1,0);
    }
    rep(i,0,n){
        ae(n+i,end,1,0);
    } 
    ll ans = minCostFlow(start,end,n,2*n+2);
    ll dd[110][110];
    clr(dd,0);
    rep(y,0,n){
        rep(x,0,n){
            rep(i,0,G[y].sz){
                edge e = G[y][i];
                if(e.cap==0){
                    dd[y][e.to-n] = 1;
                }
            }
        }
    }
    cout << ans << endl;
    ll c = 0;
    rep(y,0,n){
        rep(x,0,n){
            if(vs[y][x]=='o'&&dd[y][x]==0){
                c++;
            }
            if(vs[y][x]=='.'&&dd[y][x]==1){
                c++; 
            }
        }
    }
    cout << c << endl;
    rep(y,0,n){
        rep(x,0,n){
            if(vs[y][x]=='o'&&dd[y][x]==0){
                cout << y+1 << " " << x+1 << " erase" << endl; 
            }
            if(vs[y][x]=='.'&&dd[y][x]==1){
                cout << y+1 << " " << x+1 << " write" << endl; 
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4140