//This is written in C programming language (not C++)!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

void main()
{
    srand(time(NULL));
    int n, u, v, q, i, k, max_n = 100000;
    if(rand()%100 < 60) //in 70% of the tests
    {
        max_n = 40000;
    }
    if(rand()%100 < 30) //in 30% of the tests
    {
        max_n = 1000;
    }
    do
    {
        scanf("%d", &n);
        getchar();
    } while (n < 1 || n > max_n);
    int subord[n][n-1];
    int subord_count[n];

    for (i = 0; i < n; i++)
    {
        for (k = 0; k < n - 1; k++)
        {
            subord[i][k] = 0;
        }
        subord_count[n] = 0;
    }

    for (i = 0; i < n - 1; i++)
    {
        scanf("%d %d", &u, &v);
        subord[u-1][subord_count[u-1]] = v;
        subord_count[u-1]++;
    }

    scanf("%d", &q);
    int ans[q][2];

    for (i = 0; i < q; i++)
    {
        scanf("%d", &ans[i][0]);
        ans[i][1] += subord_count[q-1];
        //
    }

    printf("\n");

    for (i = 0; i < q; i++)
    {
        printf("%d\n", ans[i][1]);
    }
}
