#include<bits/stdc++.h>
#define MAX 301
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

struct edge{ int to,cap,cost,rev; };
 
int v;
vector<edge> e[MAX];
int h[MAX];
int dist[MAX];
int prevv[MAX],preve[MAX];

void add_edge(int from,int to,int cap,int cost){
  e[from].push_back((edge){to,cap,cost,(int)e[to].size()});
  e[to].push_back((edge){from,0,-cost,(int)e[from].size()-1});
}
 
int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+v,0);
  fill(prevv,prevv+MAX,0);
  fill(preve,preve+MAX,0);
  while(f>0){
    priority_queue<pii,vector<pii>,greater<pii> > pq;
    fill(dist,dist+v,inf);
    dist[s]=0;
    pq.push(pii(0,s));
    while(pq.size()){
      pii p=pq.top();
      pq.pop();
      int u=p.second;
      if(dist[u]<p.first)continue;
      for(int i=0;i<e[u].size();i++){
        edge &E=e[u][i];
        if(E.cap>0 && dist[E.to]>dist[u]+E.cost+h[u]-h[E.to]){
          dist[E.to]=dist[u]+E.cost+h[u]-h[E.to];
          prevv[E.to]=u;
          preve[E.to]=i;
          pq.push(pii(dist[E.to],E.to));
        }
      }
    }
    if(dist[t]==inf)return -1;
    for(int i=0;i<v;i++)h[i]+=dist[i];
 
    int d=f;
    for(int u=t;u!=s;u=prevv[u]){
      d=min(d,e[prevv[u]][preve[u]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int u=t;u!=s;u=prevv[u]){
      edge &E=e[prevv[u]][preve[u]];
      E.cap-=d;
      e[u][E.rev].cap+=d;
    }
  }
  return res;
}

int n;
int W[MAX][MAX],E[MAX][MAX];
string F[MAX];
int used[MAX][MAX];

void solve(){
  int sum = 0,cnt = 0;
  FOR(i,0,n)fill(used[i],used[i]+n,0);
  FOR(i,0,n){
    FOR(j,0,n){
      if(F[i][j]=='.')add_edge(i,j+n,1,W[i][j]);
      else {
        sum+=E[i][j];
        cnt++;
        used[i][j]=1;
        add_edge(i,j+n,1,-E[i][j]);
      }
    }
  }
  int s=n+n,t=s+1;
  v=t+1;
  FOR(i,0,n)add_edge(s,i,1,0);
  FOR(i,0,n)add_edge(i+n,t,1,0);
  int ans = min_cost_flow(s,t,n);
  cout<<sum+ans<<endl;
  vector<pair<string,pair<int,int> > > op;
  FOR(i,0,n){
    FOR(j,0,e[i].size()){
      edge a=e[i][j];
      if(a.cap!=0)continue;
      if(a.cost<1){
        cnt-=1;
        used[i][j]=0;
      }
      else {
        cnt+=1;
        used[i][j]=2;
      }
    }
  }
  cout<<cnt<<endl;
  FOR(i,0,n){
    FOR(j,0,n){
      if(used[i][j]==1)cout<<i+1<<" "<<j+1<<" erase"<<endl;
      if(used[i][j]==2)cout<<i+1<<" "<<j+1<<" write"<<endl;
    }
  }
}

int main()
{
  cin>>n;
  FOR(i,0,n)FOR(j,0,n)cin>>W[i][j];
  FOR(i,0,n)FOR(j,0,n)cin>>E[i][j];
  FOR(i,0,n)cin>>F[i];
  solve();
  return 0;
}

