#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <string.h>
#include <map>
using namespace std;
map<int,vector<int> > G;
int ans;
int n;
int x,y;
int count_;
void init()
{
G.clear();
}
void read()
{
int a,b;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
}
void bfs()
{
map<int,int> vis;
queue<int> q;
ans=G.size();
vis[x]=0;
q.push(x);
while(!q.empty())
{
int k=q.front();
q.pop();
ans--;
if(vis[k]<y)
{
for(int i=0;i<G[k].size();i++)
{
int m=G[k][i];
if(vis.count(m)==0)
{
vis[m]=vis[k]+1;
q.push(m);
}
}
}
}
}
int main()
{
while(scanf("%d",&n),n)
{
init();
read();
while(scanf("%d%d",&x,&y) && x &&y)
{
count_++;
bfs();
cout<<"Case "<<count_<<": "<<ans<<" nodes not reachable from node "
<<x<<" with TTL = "<<y<<"."<<endl;
}
}
return 0;
}