// Arup Guha
// 4/3/2017
// Solution to 1991 UCF HS Contest Problem: Sticks and Stones

import java.util.*;

public class names {

	public static int n;
	public static String[] list;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		// Process each case.
		while (stdin.hasNext()) {

			// Read and tokenize.
			String whole = stdin.next();
			StringTokenizer tok = new StringTokenizer(whole,"-");
			n = tok.countTokens();
			list = new String[n];
			for (int i=0; i<n; i++) list[i] = tok.nextToken();

			// Go through each level.
			int i;
			for (i=0; (1<<i)<n; i++)

				// Go through each marriage in this generation.
				for (int j=0; j<n; j+=(1<<(i+1)))

					System.out.println("Generation "+(i+1)+": A "+get(i,j)+" marries a "+get(i,j+(1<<i)));

			// Last line.
			System.out.println("Generation "+(i+1)+": The "+whole+" children");
			System.out.println();
		}
	}

	// Just put together the name starting at start using 2^skip consecutive names.
	public static String get(int skip, int start) {
		String res = list[start];
		for (int i=start+1; i<start+(1<<skip); i++)
			res = res + "-" + list[i];
		return res;
	}
}