Electronic Document Security#3024

Electronic Document Security

1 second
64 megabytes
Very easy

The Tyrell Corporation uses modern electronic document workflow systems that control all aspects of document creation, viewing, editing, and distribution. Document security is managed via access control lists (ACLs). An ACL defines a set of entities that have access to a document, and for each entity specifies the set of rights it has. Entities are represented by uppercase letters and may be individuals or groups. Rights are represented by lowercase letters; for example: (append), (delete), (edit), and (read).

The ACL for a document is stored with the document, but there is also a separate ACL log stored on a separate log server. All documents start with an empty ACL, giving no rights to anyone. Every time the ACL for a document changes, a new entry is recorded in the log. An entry is of the form where is a non-empty set of entities, is a non-empty set of rights, and is either , , or . An entry E+R means to grant all rights in to all entities in . An entry E-R means to remove all rights in from all entities in . An entry E=R means that all entities in have exactly the rights in and no others. An entry may be redundant if it grants a right already possessed or removes a right not possessed. Logs are comma-separated lists of entries, given chronologically from oldest to newest. Entries are cumulative; in case of conflict, newer entries override the rights of older entries.

Periodically, the Tyrell Corporation runs security checks using the logs to compute the current ACL for each document and compares it with the ACL actually stored with the document. Mismatches indicate breaches of security. Your task is to write a program that, given an ACL log, computes the current ACL.

Input

The input consists of one or more ACL logs, each – characters long, each on its own line, followed by a line containing only "#" to signal the end of input. Logs have the format as described above and contain no whitespace.

Output

For each log, output a line containing the log number (logs are numbered starting at one), followed by a colon, then the current ACL in the following format:

(1) No spaces appear in the output;

(2) Entities are listed in alphabetical order;

(3) Rights for each entity are listed in alphabetical order;

(4) Entities with no current rights are omitted (even if they appear in the log entry), so the ACL may be empty;

(5) If two or more consecutive entities have exactly the same rights, those rights are displayed only once, after the list of entities.

Examples

Example 1

Loading
Loading