<Problem>
https://www.spoj.com/PTIT/problems/BCBASEAD/
#include <iostream>
#include <string>
using namespace std;
string s[1000];
int d[1000000];
void create(int number) {
d[2] = 0;
s[0] = "{}";
int n = 1;
while (n <= number) {
s[n] = "{" + s[0];
for (int i = 1; i <= n - 2; i++) {
s[n] = s[n] + "," + s[i];
}
if (n > 1) {
s[n] = s[n] + +"," + s[n - 1] + "}";
}
else s[n] = s[n] + "}";
d[s[n].length()] = n;
n++;
}
}
int main() {
create(15);
int t;
cin >> t;
cin.ignore();
while (t--) {
string s1;
string s2;
getline(cin, s1);
getline(cin, s2);
cout << s[d[s1.length()] + d[s2.length()]] << endl;
}
return 0;
}