// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 123456789012345LL
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-10
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
using namespace std;
// mylittledoge
vector<int> ans;
bool sol;
vector<int> Vi;
vector< vector<bool> > B;
vector< vector<bool> > B2;
void bt(int k) {
if(k == 9) {
sol =true;
return;}
int mx =Vi.size();
if(k%3 == 0 && k > 0) mx =ans[k-3];
else if(k > 0) mx =ans[k-1];
for(int q =0; q < mx; q++) {
ans[k] =q;
bool ok =true;
for(int i =0; i < k; i++) ok =ok&B[ans[k]][ans[i]];
if(!ok) continue;
for(int i =k-k%3; i < k; i++) ok =ok&B2[ans[k]][ans[i]];
if(!ok) continue;
bt(k+1);
if(sol) return;}
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
srand(time(0));
string s,P;
while(P.size() < 10000000) {
cin >> s;
if(s.empty()) break;
P +=s;}
map<string,int> perm;
vector<int> Perm(9);
for(int i =0; i < 9; i++) Perm[i] =i+1;
vector<string> Pi(362880);
while(true) {
int a =perm.size();
if(Perm.size() > 362880) break;
s.clear();
for(int i =0; i < 9; i++) s +=('0'+Perm[i]);
perm[s] =a;
Pi[a] =s;
if(!next_permutation(Perm.begin(),Perm.end())) break;}
vector<int> V(362880,20000000);
for(int i =0; i < (int)P.length()-9; i++) if(perm.find(P.substr(i,9)) != perm.end()) {
if(V[perm[P.substr(i,9)]] == 20000000) Vi.push_back(perm[P.substr(i,9)]);
V[perm[P.substr(i,9)]] =min(V[perm[P.substr(i,9)]],i+1);}
B.resize(Vi.size(),vector<bool>(Vi.size(),true));
for(uint i =0; i < Vi.size(); i++) for(uint j =i; j < Vi.size(); j++)
for(int k =0; k < 9; k++) if(Pi[Vi[j]][k] == Pi[Vi[i]][k]) {
B[i][j] =B[j][i] =false;
break;}
B2.resize(Vi.size(),vector<bool>(Vi.size(),true));
for(uint i =0; i < Vi.size(); i++) for(uint j =i; j < Vi.size(); j++)
for(int a =0; a < 3; a++) for(int b =0; b < 3; b++) for(int c =0; c < 3; c++)
if(Pi[Vi[i]][3*a+b] == Pi[Vi[j]][3*a+c]) B2[i][j] =B2[j][i] =false;
cout << Vi.size() << "\n";
ans.resize(9,0);
sol =false;
cerr << "start\n";
bt(0);
cout << sol << endl;
for(int i =0; i < 9; i++) cout << Pi[Vi[ans[i]]] << " " << V[Vi[ans[i]]] << "\n";
return 0;}
// look at my code
// my code is amazing