#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include<set>

using namespace std;

// 函数:判断是否为唯一可译码
set <string> s;
bool y = true;
bool cheak(string f, int ch, std::vector<std::string> c, int n) {
	if (y == false) {
		return y;
	}
	string a, b;
	for (int i = 0; i < n; i++) {
		if (c[i] == f && (ch < 0 || (ch >= 0 && ch != i))) {
			y = false;
			return y;
		}
		else if (c[i] == f && ch == i) {
			continue;
		}
		else if (c[i].length() > f.length()) {
			a = c[i];
			b = f;
		}
		else {
			b = c[i];
			a = f;
		}
		a.erase(0, b.length());
		if (s.find(a) == s.end() && a.length() != 0) {
			//cout << a << " ";
			s.insert(a);
			cheak(a, -1, c, n);
		}
	}
	return y;
}

bool  isUniqueDecodable(std::vector<std::string> codes) {
	bool a = true;
	int n = codes.size();
	for (int i = 0; i < n; i++) {
		if (y == false)
		{
			break;
		}
		cheak(codes[i], i, codes, n);
	}
	return y;
}

int main() {
    std::ifstream fin("in3.txt");
    std::ofstream fout("out3.txt");
    std::vector<std::string> codes;
    std::string code;

    if (!fin.is_open() || !fout.is_open()) {
        std::cerr << "没有这个文件!" << std::endl;
        return 1;
    }

    int cnt = 0;
    while (fin >> code) {
        if (code == "$") {
            // 处理一组码
            std::string ans = "第" + std::to_string(++cnt) + "组";

            fout << (isUniqueDecodable(codes) ? ans + "是" : ans + "不是") << std::endl;
			s.clear();
			y = true;
			codes.clear(); // 清空codes向量以处理下一组码
        }
        else {
            codes.push_back(code);
        }
    }

    fin.close();
    fout.close();

    return 0;
}