#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
using namespace std;
using Weight = int;
using Array = vector<int>;
using Matrix = vector<Array>;
constexpr int INF = 1000000000;


pair<Weight, Array> hungarian(const Matrix &m) {
  int n = m.size();
  int p, q;
  Array fx(n, INF), fy(n, 0);
  vector<int> x(n, -1), y(n, -1);
  //REP(i,n)REP(j,n) fx[i] = max(fx[i], m[i][j]);
  for (int i = 0; i < n; ) {
    vector<int> t(n, -1), s(n+1, i);
    for (p = q = 0; p <= q && x[i] < 0; ++p)
      for (int k = s[p], j = 0; j < n && x[i] < 0; ++j)
        if (fx[k] + fy[j] == m[k][j] && t[j] < 0) {
          s[++q] = y[j], t[j] = k;
          if (s[q] < 0)
            for (p = j; p >= 0; j = p)
              y[j] = k = t[j], p = x[k], x[k] = j;
        }
    if (x[i] < 0) {
      Weight d = INF;
      for (int k = 0; k <= q; ++k)
        for (int j = 0; j < n; ++j)
          if (t[j] < 0) d = min(d, fx[s[k]] + fy[j] - m[s[k]][j]);
      for (int j = 0; j < n; ++j) fy[j] += (t[j] < 0 ? 0 : d);
      for (int k = 0; k <= q; ++k) fx[s[k]] -= d;
    } else ++i;
  }
  Weight ret = 0;
  for (int i = 0; i < n; ++i) ret += m[i][x[i]];
  return make_pair(ret, x);
}

int main() {
  int n;
  cin>>n;
  Matrix w(n, Array(n));
  REP(i,n)REP(j,n) cin >> w[i][j];
  Matrix e(n, Array(n));
  REP(i,n)REP(j,n) cin >> e[i][j];
  vector<string> m(n);
  Matrix mat(n, Array(n));
  int cost = 0;
  REP(i,n) {
    cin>>m[i];
    REP(j,n) {
      if (m[i][j] == 'o') {
        mat[i][j] = 1000 + e[i][j];
        cost += e[i][j];
      } else {
        mat[i][j] = 1000 - w[i][j];
      }
    }
  }
  auto res = hungarian(mat);
  cout << (n*1000 - res.first + cost) << endl;
  int cnt = 0;
  stringstream ss;
  REP(i,n)REP(j,n) {
    if (m[i][j] == 'o') {
      if (res.second[i] != j) {
        ss << (i+1) << ' ' << (j+1) << " erase" << endl;
        ++cnt;
      }
    } else {
      if (res.second[i] == j) {
        ss << (i+1) << ' ' << (j+1) << " write" << endl;
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
  cout << ss.str() << flush;
  return 0;
}