#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; getchar(); while(t--) { vector<char>v; string s1,s2; cin>>s1>>s2; for(int i=0; i<s1.length(); i++) { if(s2.find(s1[i])!=-1) { v.push_back(s1[i]); int k=s2.find(s1[i]); s2.erase(k,1); } } sort(v.begin(),v.end()); if(v.size()==0) { cout<<-1<<endl; } else { for(int i=0; i<v.size(); i++) { cout<<v[i]; } cout<<endl; } } return 0; } |
Double click to view unformatted code.