#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <unordered_map>
using namespace std;
typedef pair<int, string> PIS;
int cv[13][5];
string s, t = "111111111111";
unordered_map<string, int> dis;
unordered_map<string, PIS> pre;
priority_queue<PIS, vector<PIS>, greater<PIS>> q;
int f(string c) {
int cnt = 0;
for(int i = 0; i < 12; i++) {
if(c[i] != '1') cnt += ('5' - c[i]);
}
return cnt / 2 + (cnt % 2);
}
void a_star() {
q.push({f(s), s});
dis[s] = 0;
while(!q.empty()) {
string cur = q.top().second;
q.pop();
if(cur == t) break;
for(int i = 0; i < 12; i++) {
if(cur[i] == '1') continue;
int j = cv[i][cur[i] - '0'] - 1;
string p = cur;
p[i]++; p[j]++;
if(p[i] == '5') p[i] = '1';
if(p[j] == '5') p[j] = '1';
if(!dis.count(p)) {
dis[p] = dis[cur] + 1;
pre[p] = {i + 1, cur};
q.push({dis[p] + f(p), p});
}
}
}
}
int main()
{
for(int i = 0; i < 12; i++)
for(int j = 0; j <= 4; j++)
cin >> cv[i][j];
for(int i = 0; i < 12; i++) s += to_string(cv[i][0]);
a_star();
cout << dis[t] << endl;
vector<int> op;
while(t != s) {
op.push_back(pre[t].first);
t = pre[t].second;
}
for(int i = op.size() - 1; i >= 0; i--) cout << op[i] << " ";
return 0;
}