#include <bits/stdc++.h>
using namespace std;

vector<int> g[10];

set<string> ans;

vector<int> path;

void addCur() {
	string s = "";
	for (auto to : path)
		s += to + '0';
	ans.insert(s);
}

void dfs(int v) {
	path.push_back(v);
	if (v == 8)
		addCur();
	for (auto to : g[v])
		dfs(to);
	path.pop_back();
}

int32_t main() {
    int x, y;
    while (1) {
		cin >> x;
        if (x < 0) break;
        cin >> y;
        g[--x].push_back(--y);
    }
    for (int i = 0; i < 10; ++i) {
		cout << "g[" << i+1 << "] = {";
		for (auto to : g[i])
			cout << to+1 << ",";
		cout << "}" << endl;
    }
    dfs(0);
    cout << ans.size() << endl;
    for (auto to : ans)
    	cout << to << endl;
    return 0;
}

