#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110

/* Minimum Cost Flow */

struct MinimumCostFlow{

  typedef pair<int,int> P;

  struct edge {
    int to, cap, cost, rev;
    edge(int a, int b, int c, int d):to(a), cap(b), cost(c), rev(d) {}
  };

  vector<vector<edge>> G;
  vector<int> h, dist, prevv, preve;
  int V;

  MinimumCostFlow(int v):
    G(v, vector<edge>()), prevv(v, 0), preve(v, 0), V(v) {}

  int add_edge(int from, int to, int cap, int cost){
    int id = G[from].size();

    G[from].push_back(edge(to, cap, cost, G[to].size()));
    G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));

    return id;
  }

  int solve(int s, int t, int f){
    int res = 0;
    h.assign(V,0);
    while(f > 0){
      priority_queue<P, vector<P>, greater<P>> pq;
      dist.assign(V, INF);
      dist[s] = 0;
      pq.push(P(0, s));
      while(pq.size()){
        P p = pq.top(); pq.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;

        for(int i = 0; i < (int)G[v].size(); i++){
          edge &e = G[v][i];
          int d = dist[v] + e.cost + h[v] - h[e.to];
          if(e.cap > 0 && dist[e.to] > d){
            dist[e.to] = d;
            prevv[e.to] = v;
            preve[e.to] = i;
            pq.push(P(dist[e.to], e.to));
          }
        }
      }
      if(dist[t] == INF) return -1;

      for(int v = 0; v < V; v++) h[v] += dist[v];

      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 * h[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(){
  int N, W[SIZE][SIZE], E[SIZE][SIZE], id[SIZE][SIZE];
  char F[SIZE][SIZE];

  scanf("%d", &N);

  for (int i=0; i<N; i++)
    for (int j=0; j<N; j++)
      scanf("%d", W[i]+j);

  for (int i=0; i<N; i++)
    for (int j=0; j<N; j++)
      scanf("%d", E[i]+j);


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

  int B = 1000;
  int ans = 0;

  MinimumCostFlow flow(2 * N + 2);

  for (int i=0; i<N; i++) {
    scanf("%s", F[i]);

    for (int j=0; j<N; j++) {
      if (F[i][j] == 'o') {
        id[i][j] = flow.add_edge(i, N + j, 1, B - E[i][j]);
        ans += E[i][j];
      } else {
        id[i][j] = flow.add_edge(i, N + j, 1, B + W[i][j]);
      }
    }
  }

  for (int i=0; i<N; i++) {
    flow.add_edge(S, i, 1, 0);
    flow.add_edge(i + N, T, 1, 0);
  }

  int res = flow.solve(S, T, N);

  assert(res >= 0);
  ans = ans + res - N * B;

  debug(ans);

  vector<pair<int,int>> query;

  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if (flow.G[i][id[i][j]].cap == 0) {
        if (F[i][j] == '.') query.push_back({i, j});
      } else {
        if (F[i][j] == 'o') query.push_back({i, j});
      }
    }
  }

  printf("%d\n", ans);
  printf("%d\n", (int)query.size());

  for (int i=0; i<query.size(); i++) {
    int y = query[i].first;
    int x = query[i].second;

    printf("%d %d ", y+1, x+1);

    if (F[y][x] == 'o') puts("erase");
    if (F[y][x] == '.') puts("write");
  }

  return 0;
}



Measured memory_bytes: 3480