/** * author: otera **/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60 ; const ll mod=1e9+7 ; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair P; typedef pair LDP; typedef pair LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } vector> calc_nxt(string s) { int n = (int)s.size(); vector> res(n + 1, vector(26, n)); for(int i = n - 1; i >= 0; -- i) { rep(j, 26) res[i][j] = res[i + 1][j]; res[i][s[i] - 'a'] = i; } return res; } void solve() { string s, t; cin >> s >> t; int n = (int)s.size(), m = (int)t.size(); auto nxts = calc_nxt(s); auto nxtt = calc_nxt(t); vector sub(n + 1, -1); sub[n] = m; int j = m - 1; for(int i = n - 1; i >= 0; -- i) { while(j >= 0 and s[i] != t[j]) -- j; sub[i] = j; } if(sub[0] != -1) { cout << -1 << endl; return; } string ans = ""; int i = 0; j = 0; while(1) { rep(k, 26) { if(nxts[i][k] == n) continue; else if(nxtt[j][k] == m) { ans += (char)('a' + k); cout << ans << endl; return; } else { int ni = nxts[i][k] + 1, nj = nxtt[j][k] + 1; if(sub[ni] >= nj) continue; ans += (char)('a' + k); i = ni, j = nj; } } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }