#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll > pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef vector<string> vs;
#define all (v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define rep(i, n) for(ll i=0;i<(int)(n);++i)
#define repi(i, j, n) for(ll i=(j);i<(int)(n);++i)
#define repd(i, j, n) for(ll i=(j);i>=(int)(n);--i)
#define repa(i, j, v) rep(i, sz(v)) rep(j, sz(v[0]))
#define lp(i, cnt) for(ll i=0;i<(cnt);++i)
#define REP(i,start,end) for(ll i = start ; i<end ; i++)
#define eps 1.e-18
#define MOD 1000000007
set<string >result;
void BT(string s1, string s2, int n, string temp, int i, int j) {
if (temp.size() == n) {
result.insert(temp);
return;
}
if (i < s1.size())
BT(s1, s2, n, temp + s1[i], i + 1, j);
if (j < s2.size())
BT(s1, s2, n, temp + s2[j], i, j + 1);
}
int main() {
ios_base::sync_with_stdio(false);
int t;
cin>>t;
while (t--) {
result.clear() ;
string s1, s2;
cin >> s1>>s2;
BT(s1, s2, s1.size() + s2.size(), "", 0, 0);
for(set<string>::iterator t = result.begin() ; t!=result.end() ; t++){
cout<<*t<<endl;
}
cout<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8bGwsIGxsID4gcGlpOwp0eXBlZGVmIHZlY3RvcjxpbnQ+IHZpOwp0eXBlZGVmIHZlY3RvcjxwaWk+IHZwOwp0eXBlZGVmIHZlY3RvcjxzdHJpbmc+IHZzOwoKCiNkZWZpbmUgYWxsICh2KSAgICAgICAgICAgICgodikuYmVnaW4oKSksICgodikuZW5kKCkpCiNkZWZpbmUgc3oodikgICAgICAgICAgICAgKChpbnQpKCh2KS5zaXplKCkpKQojZGVmaW5lIHJlcChpLCBuKSAgICAgICAgIGZvcihsbCBpPTA7aTwoaW50KShuKT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