#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
struct edge{
    int to, cost, cap, rev;
    edge(int to, int cost, int cap, int rev)
        :to(to),cost(cost),cap(cap),rev(rev){}
    edge(){}
};
 
int min_cost_flow(int s, int g, int f, vector<vector<edge> > &adj){
    int n = adj.size();
    int res = 0;
    while(f > 0){
        vector<int> prevv(n), preve(n);
        vector<int> mincost(n, inf);
        mincost[s] = 0;
        while(1){
            bool update = false;
            for(int i=0; i<n; i++){
                if(mincost[i] == inf) continue;
                for(int j=0; j<(int)adj[i].size(); j++){
                    edge &e = adj[i][j];
                    if(e.cap>0 && mincost[i] +e.cost < mincost[e.to]){
                        mincost[e.to] = mincost[i] +e.cost;
                        prevv[e.to] = i;
                        preve[e.to] = j;
                        update = true;
                    }
                }
            }
            if(!update) break;
        }
        if(mincost[g] == inf){
            return -1;
        }
         
        int d = f;
        for(int v=g; v!=s; v=prevv[v]){
            d = min(d, adj[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d*mincost[g];
        for(int v=g; v!=s; v=prevv[v]){
            edge &e = adj[prevv[v]][preve[v]];
            e.cap -= d;
            adj[v][e.rev].cap += d;
        }
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    int writecost[100][100], erasecost[100][100];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> writecost[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> erasecost[i][j];
        }
    }
    vector<string> initial(n);
    for(int i=0; i<n; i++){
        cin >> initial[i];
    }
    int initialcost = 0;
    int change[100][100] = {};
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(initial[i][j] == 'o'){
                change[i][j] = 1;
                initialcost += erasecost[i][j];
            }
        }
    }
    
    int s=0, g=2*n+1;
    vector<vector<edge>> adj(2*n+2);
    for(int i=1; i<n+1; i++){
        adj[s].emplace_back(i, 0, 1, adj[i].size());
        adj[i].emplace_back(s, 0, 0, adj[0].size()-1);
        adj[g].emplace_back(n+i, 0, 0, adj[n+i].size());
        adj[n+i].emplace_back(g, 0, 1, adj[g].size()-1);
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int cost = (change[i][j]==0)? writecost[i][j]: -erasecost[i][j];
            int from=1+i, to=n+1+j;
            adj[from].emplace_back(to, cost, 1, adj[to].size());
            adj[to].emplace_back(from, -cost, 0, adj[from].size()-1);
        }
    }
    
    int ans = initialcost +min_cost_flow(0, 2*n+1, n, adj);
    cout << ans << endl;
    int count = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(adj[1+i][1+j].cap == 0){
                change[i][j] = 1-change[i][j];
            }
            if(change[i][j] == 1){
                count++;
            }
        }
    }
    cout << count << endl;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(change[i][j] == 1){
                cout << i+1 << " " << j+1 << " ";
                if(initial[i][j] == '.') cout << "write" << endl;
                else cout << "erase" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3588