#include "testlib.h"
#define MAX_WRD 100000
#define MAX_LEN 15
using namespace std;
char errMsg[1000];
int current, total;
void fail()
{
    quit(_pe, errMsg);
}

void check(string s)
{
    if((s.length()>MAX_LEN) || (s.length()<1))
    {
        sprintf(errMsg, "Description %d is invalid: token '%s' is invalid", current, s.c_str());
        fail();
    }
    total++;
    if(total>MAX_WRD)
    {
        sprintf(errMsg, "Too many words in file!");
        fail();
    }
    for(int i=0; i<s.length(); ++i)
        if((s[i]<'a')||(s[i]>'z'))
        {
            sprintf(errMsg, "Description %d is invalid: token '%s' is invalid: character '%c' is invalid", current, s.c_str(), s[i]);
            fail();
        }
}
int main()
{
    registerValidation();
    inf.strict=true;
    int n=inf.readInt(1, MAX_WRD);
    string words[MAX_WRD+1], def[MAX_WRD+1];
    inf.readEoln();
    words[0]="", def[0]="";
    for(current=1; current<=n; ++current)
    {
        words[current]=inf.readString();
        check(words[current]);
        if(words[current]<words[current-1])
        {
            sprintf(errMsg, "Words in dictionary are not sorted: %s < %s", words[current].c_str(), words[current-1].c_str());
            fail();
        }
        int k=inf.readInt(1, MAX_WRD);
        inf.readEoln();
        for(int i=1; i<=k; ++i)
        {
            def[i]=inf.readString();
            check(def[i]);
            if(def[i]<def[i-1])
            {
                sprintf(errMsg, "Description %d is invalid: defenitions are not sorted: %s < %s", current, def[i].c_str(), def[i-1].c_str());
                fail();
            }
        }
    }
    inf.readEof();
    return 0;
}
