#include #include #include #include using namespace std; #define MAXL 41 #define MAXN 41 #define MAXNN 3010 typedef struct _simpleExpression { char var[MAXL]; char op[3]; int value; int flag; }SimpleExpression; typedef struct _complexExpression { SimpleExpression sim[MAXN]; int num; }ComplexExpression; ComplexExpression com[MAXNN]; void init() { memset (com, 0, sizeof(com)); } void getExpression(int i) { char c; int j = 0, k = 0; while ((c=getchar())!='\n' && c!=EOF) { if (c >= 'a' && c <= 'z') { com[i].sim[com[i].num].var[j++] = c; } else if (c=='>' || c=='<' || c=='=') { com[i].sim[com[i].num].op[k++] = c; } else if (c==',') { com[i].sim[com[i].num].var[j] = '\0'; com[i].sim[com[i].num].op[k] = '\0'; if (com[i].sim[com[i].num].flag==-1){ com[i].sim[com[i].num].value *= -1; } j=k=0, com[i].num++; } else if (c>='0' && c<='9') { com[i].sim[com[i].num].value = com[i].sim[com[i].num].value*10 + c-'0'; } else if (c=='-') { com[i].sim[com[i].num].flag = -1; } } if (com[i].sim[com[i].num].flag==-1){ com[i].sim[com[i].num].value *= -1; } com[i].sim[com[i].num].var[j] = '\0'; com[i].sim[com[i].num].op[k] = '\0'; j=k=0, com[i].num++; } void simpleCopy(SimpleExpression &a, SimpleExpression b) { strcpy(a.var, b.var); strcpy(a.op, b.op); a.value = b.value; } bool isIntersect(SimpleExpression a, SimpleExpression b) { if (strcmp(a.op, ">")==0) { // > if (strcmp(b.op, ">") == 0 || strcmp(b.op, ">=")==0){ return true; } else if (strcmp(b.op, "==")==0) { if (a.value < b.value)return true; } else if (strcmp(b.op, "<")==0) { if (a.value=")==0) { // >= if (strcmp(b.op, ">") == 0 || strcmp(b.op, ">=")==0){ return true; } else if (strcmp(b.op, "==")==0) { if (a.value <= b.value)return true; } else if (strcmp(b.op, "<")==0) { if (a.value")==0) { if (a.value>b.value+1)return true; } else if (strcmp(b.op, ">=")==0) { if (a.value>b.value)return true; } } else if (strcmp(a.op, "<=")==0) { // <= if (strcmp(b.op, "<") == 0 || strcmp(b.op, "<=")){ return true; } else if (strcmp(b.op, "==")==0) { if (a.value >= b.value)return true; } else if (strcmp(b.op, ">")==0) { if (a.value>b.value)return true; } else if (strcmp(b.op, ">=")==0) { if (a.value>=b.value)return true; } } else if (strcmp(a.op, "==")==0) { // == if (strcmp(b.op, ">")==0) { if (a.value > b.value)return true; } else if (strcmp(b.op, ">=")==0) { if (a.value >= b.value)return true; } else if (strcmp(b.op, "<")==0) { if (a.value < b.value)return true; } else if (strcmp(b.op, "<=")==0) { if (a.value <= b.value) return true; } else if (strcmp(b.op, "==")==0) { if (a.value == b.value)return true; } } return false; } void simplePrint(SimpleExpression *sim, int n) { for (int i = 0; i < n; ++i) { printf("%s%s%d\n", sim[i].var, sim[i].op, sim[i].value); } } void printIndex(int i) { for (int j = 0; j < com[i].num; ++j) { simplePrint(com[i].sim, com[i].num); } } bool intersect(int i, int j) { SimpleExpression tmp[2*MAXN+10]; int n = 0; for (int k = 0; k < com[i].num; ++k) { for (int x = 0; x < n; ++x) { if (strcmp(tmp[x].var, com[i].sim[k].var) == 0) { if (! isIntersect(tmp[x], com[i].sim[k])) { return false; } } } simpleCopy(tmp[n], com[i].sim[k]); n++; } for (int k = 0; k < com[j].num; ++k) { for (int x = 0; x < n; ++x) { if (strcmp(tmp[x].var, com[j].sim[k].var) == 0) { if (! isIntersect(com[j].sim[k], tmp[x])) { return false; } } } simpleCopy(tmp[n], com[j].sim[k]); n++; } // simplePrint(tmp, n); return true; } void solve(int n) { bool flag = false; for (int i = 0; i < n; ++i) { if (intersect(i, n)) { if (flag) { printf(" "); } printf("%d", i+1); flag = true; } } if (!flag) { puts("unique"); } else { printf("\n"); } } int main() { // freopen("a.txt", "w", stdout); int n; scanf ("%d", &n); //fflush(stdin); getchar(); init(); for (int i = 0; i < n; ++i) { getExpression(i); //fflush(stdin); solve(i); } return 0; }