#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
struct biHash
{
    int sz = 0;
    map<string, int> h1;
    map<int, string> h2;
    int insert(const string &s)
    {
        auto ite = h1.find(s);
        if (ite == h1.end())
        {
            int id = sz++;
            h1[s] = id;
            h2[id] = s;
            return id;
        }
        else
            return ite->second;
    }
    string &query(int key) { return h2[key]; }
    int query(const string &key) { return h1[key]; }
    void reset() { sz = 0, h1.clear(), h2.clear(); }
};
const int N = 30;
int dis[N][N], vis[N];
string s1, s2;
biHash H;
int main()
{
    for (int t = 1, n, m; scanf("%d%d", &n, &m), n | m; t++)
    {
        H.reset();
        memset(dis, 0, sizeof(dis));
        memset(vis, 0, sizeof(vis));
        for (int i = 0; i < N; i++) dis[i][i] = 1;
        for (int i = 0; i < m; i++)
        {
            cin >> s1 >> s2;
            int id1 = H.insert(s1);
            int id2 = H.insert(s2);
            dis[id1][id2] = 1;
        }
        for (int k = 0; k < n; k++)
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    dis[i][j] |= dis[i][k] & dis[k][j];
        printf("Calling circles for data set %d:\n", t);
        for (int i = 0; i < n; i++)
            if (!vis[i])
            {
                printf("%s", H.query(i).c_str());
                for (int j = 0; j < n; j++)
                    if (dis[i][j] & dis[j][i])
                    {
                        vis[j] = 1;
                        if (i != j) printf(", %s", H.query(j).c_str());
                    }
                putchar('\n');
            }
    }
    return 0;
}