#include <iostream>
using namespace std;
typedef struct node
{
char data;
struct node *lchild;
struct node *rchild;
int step;
}BTnode;
void Create(BTnode *&T)
{
char ch;
cin>>ch;
if(ch == '#')
{
T = NULL;
}
else
{
T = new BTnode;
T->data = ch;
Create(T->lchild);
Create(T->rchild);
}
}
int Level_Find(BTnode *T, char x)
{
if(T == NULL) return 0;
BTnode *a[100];
int front = -1, rear = 0;
a[0] = T, a[0]->step = 1;
while(front != rear)
{
front++;
if(a[front]->data == x) return a[front]->step;
if(a[front]->lchild) a[++rear] = a[front]->lchild, a[rear]->step = a[front]->step + 1;
if(a[front]->rchild) a[++rear] = a[front]->rchild, a[rear]->step = a[front]->step + 1;
}
return 0;
}
int Pre_Find(BTnode *T, char x, int h)
{
int l;
if(!T) return 0;
if(T->data == x) return h;
l = Pre_Find(T->lchild, x, h+1);
if(l != 0) return l;
return Pre_Find(T->rchild, x, h+1);
}
int main()
{
BTnode *T, *t;
Create(T);
cout<<Level_Find(T, 'F')<<endl;
cout<<endl;
int loc = Pre_Find(T,'Q',1);
if(loc)
cout<<loc<<endl;
else
cout<<"No Find"<<endl;
return 0;
}