#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<string>
#include<set>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
int l, r;
char val;
};
node tree[10010];
int idx;
map<char, int> ha;
string a, b;
int build(int pl, int pr, int il, int ir)
{
int t = ++idx;
if (pl > pr)
{
tree[t].val = '0';
return 0;
}
int cur = ha[a[pl]];
int l = build(pl + 1, pl + cur - il, il, cur - 1);
int r = build(pl + cur - il + 1, pr, cur + 1, pr);
tree[t].l = l;
tree[t].r = r;
tree[t].val = a[pl];
return t;
}
void dfs(int root)
{
queue<int > q;
q.push(root);
while (q.size())
{
int top = q.front();
q.pop();
cout << tree[top].val;
if (tree[top].l)
q.push(tree[top].l);
if (tree[top].r)
q.push(tree[top].r);
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> a >> b;
ha.clear();
idx = 0;
for (int i = 0; i < b.size(); i++) ha[b[i]] = i;
int root = build(0, a.size() - 1, 0, b.size() - 1);
dfs(root);
cout << endl;
}
return 0;
}
//递归建立二叉树的函数
对应该是 bfs
函数名好像有一点问题,应该是bfs,,,吧