The Pact system encodes arbitrary data structures built from records, arrays, strings and integers. An encoded structure is a string of printable characters, so it can be written to a file or sent over a network. Pact does not depend on the hardware, the operating system or the programming language. The encoder already exists. Your task is to write the decoder.
A record is a set of named components. Two records have the same type when they have components of the same types with the same names. A record has at least one component.
An array is one dimensional and is indexed from 0, and every element of an array has the same type. An array has at least one element. Two arrays have the same type when their elements have the same type, so two arrays whose elements have the same type but whose lengths differ still have the same type.
The basic encoding works as follows.
An integer is encoded as a digit string, optionally preceded by a minus sign. An integer has at most 100 digits.
12 -> 12
123456543254321 -> 123456543254321
-23 -> -23
A string consists of printable characters only (letters, digits, punctuation). It is encoded by enclosing it in double quotes. A double quote inside the string is escaped with a backslash, and a backslash inside the string is also escaped with a backslash.
Hello -> "Hello"
Say "Hello" -> "Say \"Hello\""
"\"Hello\"" -> "\"\\\"Hello\\\"\""
An array is encoded as the encodings of its elements in order, from element 0 to the last element, separated by commas and enclosed in semicolons.
[5,7,4,3] -> ;5,7,4,3;
[red,green,blue] -> ;"red","green","blue";
[[1,2,3],[4,5,6],[7,8]] -> ;;1,2,3;,;4,5,6;,;7,8;;
A record is encoded as its fields separated by commas and enclosed in semicolons. A field is encoded as the field name, then a colon, then the encoding of its value. Field names are alphanumeric, start with a letter and are case sensitive. No two fields of one record have the same name. The fields may appear in any order inside an encoding.
(x:5,y:7,n5:Fred) -> ;x:5,y:7,n5:"Fred";
Two compression rules modify this basic encoding.
First, when two or more successive array elements have the same value, that value is written once, followed by an asterisk and an integer giving the number of repetitions.
[5,5,5,7,6,6] -> ;5*3,7,6*2;
[(x:5,y:6),(x:5,y:6)] -> ;;x:5,y:6;*2;
Second, in an array of records, a field entry is omitted when its value equals the value of the field with the same name in the predecessor array element. This applies only to the top level record elements of an array, and it never allows selective omission inside a nested record. It never produces a record encoding with no fields.
[(x:5,y:6),(x:5,y:7)] -> ;;x:5,y:6;,;y:7;;
[(x:5,y:6),(x:5,y:6)] -> ;;x:5,y:6;*2;
[(a:5,b:(x:6,y:7)),(a:5,b:(x:6,y:8))] -> ;;a:5,b:;x:6,y:7;;,;b:;x:6,y:8;;;
The input holds a sequence of problems. Each problem starts with a line holding a positive integer N. The next line holds a Pact encoded string of at most 1,000 characters. Then come N lines, each holding one test.
A test is a data access: the character v followed by zero or more indices and field selectors, for example v, v[0].x, v.x.name or v.x.arr[5].str.
Every index i is an integer literal with 0≤i≤100. A test access always reaches a string or an integer, so it never refers to a whole array or a whole record. Every test access matches the encoded structure. One data structure holds at most 1,000 string and integer values in total.
A line holding 0 in place of N ends the input.
For each problem, print a line reading Problem n, where n is the problem number counting from 1. Then print N lines, each holding the string or the integer that the corresponding test reaches. Print a string without its enclosing double quotes and without the escaping backslashes. Print an integer exactly as its digits appear in the encoding.