//#pragma comment(linker,"/STACK:12000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<time.h>
#define eps 1e-15
using namespace std;
char m[20][100000]={{0}};
int a[20]={0};
char s1[100000]={0};
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	m[0][0]='{';
	m[0][1]='}';
	
	int i, j, k, t;
	a[0]=1;
	for(i=1; i<=15; i++)
	{
		m[i][0]='{';
		t=1;
		for(j=0; j<i; j++)
		{
			for(k=0; k<=a[j]; k++)
			{
				m[i][t]=m[j][k];
				t++;
			}
			m[i][t]=',';
			t++;
		}
		m[i][t-1]='}';
		a[i]=t-1;
	}
	gets(s1);
	for(i=0; i<=15; i++)
		if(strcmp(s1, m[i])==0)
		{
			j=i;
			break;
		}
	gets(s1);
	for(i=0; i<=15; i++)
		if(strcmp(s1, m[i])==0)
		{
			k=i;
			break;
		}
	for(i=0; i<=a[k+j]; i++)
		printf("%c", m[k+j][i]);
	return 0;
}