#include <iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int m[N], u, v, U[N], V[N];
    for (int i=1; i<=N; i++)
    {
        m[i]=0;
    }
    for (int i=1; i<=N-1; i++)
    {
        cin>>u>>v;
        U[i]=u;
        V[i]=v;
    }
    for (int i=1; i<=N-1; i++)
    {
        for (int j=i+1; j<=N-1; j++)
        {
            if (U[j]==V[i])
            {
                swap (U[i], U[j]);
                swap (V[i], V[j]);
            }
        }
    }
    for (int i=1; i<=N-1; i++)
    {
        cout<<U[i]<<" "<<V[i]<<endl;
        m[U[i]]=m[U[i]]+m[V[i]]+1;
    }
    cout<<m[4];
    int Q, M;
    cin>>Q;
    for (int i=0; i<Q; i++)
    {
        cin>>M;
        cout<<m[M];
    }
    return 0;
}
