# 求根结点到指定结点的路径

ABC^^DE^G^^F^^^
3
A
D
G

## Sample Output

A
ABD
ABDEG

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<iostream>

using namespace std;
typedef struct BiTNode{
char d;
struct BiTNode *l;
struct BiTNode *r;
}*BiTree,BiTreeNode;
char ch;
bool flag;

void CreateBiTree( BiTree &T)
{
char tmp;
if( flag)
scanf("%c",&tmp);
else
{
tmp = ch;
flag = true;
}

if( tmp == '^')
T = NULL;
else
{
T = new BiTreeNode;
T->d = tmp;
CreateBiTree( T->l);
CreateBiTree( T->r);
}

}

void findpath( BiTree &T, char x, vector<int> &v)
{
if( T == NULL)
return;
v.push_back( T->d);
if( T->d == x)
{
flag = 1;
for( int i = 0; i < v.size(); i++)
putchar(v[i]);
putchar(10);
return;
}
findpath( T->l, x, v);
findpath( T->r, x, v);
v.pop_back();

}

int main()
{
while( ~scanf("%c",&ch))
{
if( ch == '\n')
continue;
BiTree T = NULL;
flag = false;
CreateBiTree( T);

int n;
scanf("%d",&n);
char x;
for( int i = 1; i <= n; i++)
{
scanf(" %c",&x);
vector<int> v;
findpath( T,x,v);
//putchar(10);
}

}

return 0;
}