#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;
char m[10000000];
int getN()
{
	int s = strlen(m)-1;
	int k = -1;
	while (m[s] == '}')
	{
		s--;
		k++;
	}
	return k;
}
void gen(int n, int &pos)
{
	m[pos] = '{';
	pos++;
	for (int i = 0; i < n; i++)
	{
		gen(i, pos);
		if (i != n-1)
		{
			m[pos] = ',';
			pos++;
		}
	}
	m[pos] = '}';
	pos++;
	



}
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin >> m;
	int n1 = getN();
	cin >> m;
	int n2 = getN();
	for (int i = 0; i < sizeof(m); i++)	m[i] = 0;
	int p = 0;
	gen(n1+n2, p);
	printf("%s", m);
}