#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     bool a[n][n], fin[n][n], line[n];     for (long long i = (0); i < (n); i++) {       string s;       cin >> s;       for (long long j = (0); j < (n); j++) a[i][j] = s[j] ==  0  ? 0 : 1;     }     for (long long i = (0); i < (n); i++) {       string s;       cin >> s;       for (long long j = (0); j < (n); j++) fin[i][j] = s[j] ==  0  ? 0 : 1;     }     string s;     cin >> s;     for (long long i = (0); i < (n); i++) line[i] = s[i] ==  0  ? 0 : 1;     bool flag = 1;     for (long long i = (0); i < (n); i++) {       for (long long j = (0); j < (n); j++) {         if (a[i][j] != fin[i][j]) {           flag = 0;           break;         }       }     }     if (flag) {       cout << 0;       return;     }     bool row[n], col[n];     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     long long f = -1;     for (long long i = (0); i < (n); i++) {       if (line[i]) {         f = i;         break;       }     }     if (f == -1) {       cout << -1;       return;     }     for (long long i = (0); i < (n); i++) {       if (a[i][f] != fin[i][f]) row[i] = 1;     }     bool temp[n][n];     for (long long i = (0); i < (n); i++) {       for (long long j = (0); j < (n); j++) {         temp[i][j] = a[i][j];         if (row[i]) temp[i][j] ^= line[j];       }     }     for (long long j = (0); j < (n); j++) {       flag = 1;       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (flag) continue;       flag = 1;       col[j] = 1;       for (long long i = (0); i < (n); i++) temp[i][j] ^= line[i];       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (!flag) break;     }     if (flag) {       long long cnt = 0;       for (long long i = (0); i < (n); i++) {         cnt += row[i];         cnt += col[i];       }       cout << cnt <<   n ;       for (long long i = (0); i < (n); i++) {         if (row[i]) cout <<  row   << i <<   n ;       }       for (long long i = (0); i < (n); i++) {         if (col[i]) cout <<  col   << i <<   n ;       }       return;     }     for (long long i = (0); i < (n); i++) {       if (line[i]) row[i] ^= 1;     }     for (long long i = (0); i < (n); i++) {       for (long long j = (0); j < (n); j++) {         temp[i][j] = a[i][j];         if (row[i]) temp[i][j] ^= line[j];       }     }     for (long long j = (0); j < (n); j++) {       col[j] = 0;       flag = 1;       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (flag) continue;       flag = 1;       col[j] = 1;       for (long long i = (0); i < (n); i++) temp[i][j] ^= line[i];       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (!flag) break;     }     if (flag) {       long long cnt = 0;       for (long long i = (0); i < (n); i++) {         cnt += row[i];         cnt += col[i];       }       cout << cnt <<   n ;       for (long long i = (0); i < (n); i++) {         if (row[i]) cout <<  row   << i <<   n ;       }       for (long long i = (0); i < (n); i++) {         if (col[i]) cout <<  col   << i <<   n ;       }       return;     }     cout << -1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = (1); i < (t + 1); i++) {       solve();       cout <<   n ;     }   }   