#include<bits/stdc++.h>
using namespace std;
map< int, int > visited;
void BFS(int s, map< int, vector< int > >G)
{
queue< int >q;
q.push(s);
visited[s] = 0;
while(!q.empty())
{
int top = q.front();
for(int i=0; i<G[top].size(); i++)
{
int n = G[top][i];
if(!visited.count(n))
{
visited[n] = visited[top] + 1;
q.push(n);
}
}
q.pop();
}
}
int main()
{
int edges, cases=0;
while(scanf("%d",&edges)==1 & edges!=0)
{
map< int,vector< int > >G;
for(int i=0; i<edges; i++)
{
int x, y;
scanf("%d %d", &x, &y);
G[x].push_back(y);
G[y].push_back(x);
}
int ttl, source;
while(scanf("%d %d", &source, &ttl)==2)
{
if(source==0 && ttl==0) break;
map< int, int>::iterator it;
visited.clear();
BFS(source,G);
int count=0;
for(it=visited.begin(); it!=visited.end();++it)
{
if((*it).second>ttl){
++count;
}
}
//cout<<G.size()<<' '<<visited.size()<<endl;
count = count + G.size()-visited.size();
printf("Case %d: %d nodes not reachable from node %d with TTL = %d.\n",++cases,count, source, ttl);
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cm1hcDwgaW50LCBpbnQgPiB2aXNpdGVkOwoKdm9pZCBCRlMoaW50IHMsIG1hcDwgaW50LCB2ZWN0b3I8IGludCA+ID5HKQp7CiAgICBxdWV1ZTwgaW50ID5xOwogICAgcS5wdXNoKHMpOwogICAgdmlzaXRlZFtzXSA9IDA7CiAgICB3aGlsZSghcS5lbXB0eSgpKQogICAgewogICAgICAgIGludCB0b3AgPSBxLmZyb250KCk7CiAgICAgICAgZm9yKGludCBpPTA7IGk8R1t0b3BdLnNpemUoKTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICBpbnQgbiA9IEdbdG9wXVtpXTsKICAgICAgICAgICBpZighdmlzaXRlZC5jb3VudChuKSkKICAgICAgICAgICB7CiAgICAgICAgICAgICAgIHZpc2l0ZWRbbl0gPSB2aXNpdGVkW3RvcF0gKyAxOwogICAgICAgICAgICAgICBxLnB1c2gobik7CiAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBxLnBvcCgpOwogICAgfQp9CgoKCmludCBtYWluKCkKewogICAgaW50IGVkZ2VzLCBjYXNlcz0wOwogICAgd2hpbGUoc2NhbmYoIiVkIiwmZWRnZXMpPT0xICYgZWRnZXMhPTApCiAgICB7CiAgICAgICAgbWFwPCBpbnQsdmVjdG9yPCBpbnQgPiA+RzsKICAgICAgICBmb3IoaW50IGk9MDsgaTxlZGdlczsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHgsIHk7CiAgICAgICAgICAgIHNjYW5mKCIlZCAlZCIsICZ4LCAmeSk7CiAgICAgICAgICAgIEdbeF0ucHVzaF9iYWNrKHkpOwogICAgICAgICAgICBHW3ldLnB1c2hfYmFjayh4KTsKICAgICAgICB9CiAgICAgICAgaW50IHR0bCwgc291cmNlOwogICAgICAgIHdoaWxlKHNjYW5mKCIlZCAlZCIsICZzb3VyY2UsICZ0dGwpPT0yKQogICAgICAgIHsKICAgICAgICAgICAgaWYoc291cmNlPT0wICYmIHR0bD09MCkgYnJlYWs7CiAgICAgICAgICAgIG1hcDwgaW50LCBpbnQ+OjppdGVyYXRvciBpdDsKICAgICAgICAgICAgdmlzaXRlZC5jbGVhcigpOwogICAgICAgICAgICBCRlMoc291cmNlLEcpOwogICAgICAgICAgICBpbnQgY291bnQ9MDsKICAgICAgICAgICAgZm9yKGl0PXZpc2l0ZWQuYmVnaW4oKTsgaXQhPXZpc2l0ZWQuZW5kKCk7KytpdCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoKCppdCkuc2Vjb25kPnR0bCl7CiAgICAgICAgICAgICAgICAgICAgKytjb3VudDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICAvL2NvdXQ8PEcuc2l6ZSgpPDwnICc8PHZpc2l0ZWQuc2l6ZSgpPDxlbmRsOwogICAgICAgICAgICBjb3VudCA9IGNvdW50ICsgRy5zaXplKCktdmlzaXRlZC5zaXplKCk7CiAgICAgICAgICAgIHByaW50ZigiQ2FzZSAlZDogJWQgbm9kZXMgbm90IHJlYWNoYWJsZSBmcm9tIG5vZGUgJWQgd2l0aCBUVEwgPSAlZC5cbiIsKytjYXNlcyxjb3VudCwgc291cmNlLCB0dGwpOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9Cg==