#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define pb push_back #define mp make_pair #define sz(a) ((int)(a.size())) #define all(a) a.begin(),a.end() #define EPS 1e-11 #define REP(i,n) for(int (i)=0;i<(n);++i) #define REPS(i,n) for(int(i)=0;i<(n.size());++i) #define FOR(i,a,b) for(int(i)=(a);i<=(b);++i) #define FORD(i,a,b) for(int(i)=(a);i>=(b);--i) #define FORE(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it) #define LL long long #define SQR(a) ((a)*(a)) struct slovo { char s[20]; }; bool operator<(const slovo &a,const slovo &b) { return strcmp(a.s,b.s)<0; } deque v1,v2,ret; multiset m1,m2; char s[20]; slovo SLOVO(char *s) { slovo ret; sprintf(ret.s,"%s",s); return ret; } slovo S; int main() { while(1) { scanf("%s",s); if (strcmp(s,".")==0) break; S=SLOVO(s); v1.clear(); v2.clear(); m1.clear(); m2.clear(); v1.pb(S); m1.insert(S); while(1) { scanf("%s",s); if (strcmp(s,".")==0) break; S=SLOVO(s); v1.pb(S); m1.insert(S); } while(1) { scanf("%s",s); if (strcmp(s,".")==0) break; S=SLOVO(s); v2.pb(S); m2.insert(S); } ret.clear(); while(sz(v1)||sz(v2)) { if (sz(v1)==0) { ret.pb(v2[0]); m2.erase(m2.find(v2[0])); v2.pop_front(); } else if (sz(v2)==0) { ret.pb(v1[0]); m1.erase(m1.find(v1[0])); v1.pop_front(); } else if (strcmp(v1[0].s,v2[0].s)==0) { ret.pb(v1[0]); m1.erase(m1.find(v1[0])); m2.erase(m2.find(v2[0])); v1.pop_front(); v2.pop_front(); } else { if (strcmp(v1[0].s,v2[0].s)<0) { if (m2.count(v1[0])==0) { ret.pb(v1[0]); m1.erase(m1.find(v1[0])); v1.pop_front(); } else if (m1.count(v2[0])==0) { ret.pb(v2[0]); m2.erase(m2.find(v2[0])); v2.pop_front(); } else { ret.pb(v1[0]); m1.erase(m1.find(v1[0])); v1.pop_front(); } } else { if (m1.count(v2[0])==0) { ret.pb(v2[0]); m2.erase(m2.find(v2[0])); v2.pop_front(); } else if (m2.count(v1[0])==0) { ret.pb(v1[0]); m1.erase(m1.find(v1[0])); v1.pop_front(); } else { ret.pb(v2[0]); m2.erase(m2.find(v2[0])); v2.pop_front(); } } } } REP(i,sz(ret)) { if (i) putchar(' '); printf("%s",ret[i].s); } printf(" .\n"); } return 0; }