//* Problem  : H
//* Contest  : acm.tju.edu.cn
//* Origin   : Greater New York 2000
//* Type     : Solution
//* Date     : 2008.05.29
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 8.0

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

#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <iostream>
using namespace std;
#define int64 long long

int n, v[1024], a[1024][1024], pr[1024];

void add_edge(int from, int to)
{
	a[from][0]++; a[from][a[from][0]] = to;
}

void bfs(int vv, int vn)
{
	queue <int> q; q.push(vv); v[vv] = 1;
	while (!q.empty())
	{
		vv = q.front(); q.pop();
		for (int i = 1; i <= a[vv][0]; i++)
		{
			int t = a[vv][i];
			if (t != vn && !v[t])
			{
				q.push(t);
				v[t] = 1;
			}
		}
	}
}

int count2(int vv)
{
	memset(v, 0, sizeof(v));
	int res = 0;
	for (int i = 1; i <= 1000; i++)
		if (pr[i] && i != vv && !v[i])
		{
			bfs(i, vv); res++;
		}
	return res;
}

int main()
{
#ifdef _DEBUG
 	freopen("h.in", "r", stdin);
// 	freopen("h.out", "w", stdout);
#endif
	int it = 0, f;
	while (1)
	{
		memset(a, 0, sizeof(a));
		memset(pr, 0, sizeof(pr));
		int v1, v2;
		scanf("%d", &v1);
		if (!v1) break;
		printf("Network #%d\n", ++it);
		f = 0;
		scanf("%d", &v2);
		add_edge(v1, v2); pr[v1] = 1;
		add_edge(v2, v1); pr[v2] = 1;
		while (scanf("%d", &v1) == 1 && v1)
		{
			scanf("%d", &v2);
			add_edge(v1, v2); pr[v1] = pr[v2] = 1;
			add_edge(v2, v1);
		}
		int k;
		for (int i = 1; i <= 1000; i++)
			if (pr[i] && (k = count2(i)) > 1)
			{
				printf("  SPF node %d leaves %d subnets\n", i, k);
				f = 1;
			}
		if (!f)
			printf("  No SPF nodes\n");
		printf("\n");
	}
	return 0;
}
