Under construction

Still being built. Things may change

Jeju Chocolate Guard

Time limit1sMemory limit512 MB

Summary
After each eating event, print the remaining chocolate total in a base set by the previous total's ones digit, then list the kinds with nonzero counts sorted by count.
Level

Easy3 of 10

Topics
Implementation, Simulation, Sorting
Solved
No attempts yet

Problem

Last week, a teacher who visited Jeju Island hid Jeju chocolates in the refrigerator and has been eating them in secret.

Photo 1. A photo of the inside of the teacher's actual refrigerator

Sharp-eyed students noticed and stole some of the chocolates! The teacher wants to write the number of remaining chocolates on a sticky note so that students stop eating them. Students could change the number, so the teacher will write it according to a specific rule.

There are 5 kinds of chocolate: Hallabong (H), tangerine (T), Baengnyeoncho (C), kiwi (K), and green tea (G).

The rule for writing the remaining count is as follows.

  1. On the first line, write the total number of remaining chocolates, followed directly by 7H (a word that renders the Korean counter 개 in ASCII characters).
    • Write the total in the base equal to the ones digit of the total from the previous step.
    • If the ones digit of the previous total is 0 or 1, write it in decimal.
  2. On the second line, write the letter for each kind in order of remaining count, largest first, with no spaces.
    • Do not write the letter for a kind with 0 remaining.
    • If several kinds have the same count, the one whose letter comes first alphabetically goes first.
    • If the total remaining count is 0, write NULL.

Write a program that prints the counts to put on the sticky note.

Input

The first line contains the remaining counts of each kind HH, TT, CC, KK, GG. HH, TT, CC, KK, GG are the remaining counts of Hallabong, tangerine, Baengnyeoncho, kiwi, and green tea chocolates, respectively.

The second line contains the number of times chocolates are eaten, MM.

From the third line through line M+2M+2, each line gives the number of each kind eaten in one eating event: hih_i, tit_i, cic_i, kik_i, gig_i. These are the numbers of Hallabong, tangerine, Baengnyeoncho, kiwi, and green tea chocolates eaten.

Output

Print the output in the format described in the problem, using a total of M×2M \times 2 lines.

Constraints

  • 1≤H,T,C,K,G≤1 000 0001 \le H, T, C, K, G \le 1\,000\,000
  • 1≤M≤1 0001 \le M \le 1\,000
  • 0≤hi≤H0 \le h_i \le H
  • 0≤ti≤T0 \le t_i \le T
  • 0≤ci≤C0 \le c_i \le C
  • 0≤ki≤K0 \le k_i \le K
  • 0≤gi≤G0 \le g_i \le G
  • The sum of eaten chocolates of each kind is guaranteed to be less than or equal to the initial count of that kind.

Examples2

  1. Example 1

    Input
    10 10 10 10 10
    3
    1 1 1 1 1
    1 2 3 4 5
    5 4 3 2 1
    
    Expected output
    457H
    CGHKT
    1107H
    HTCKG
    157H
    CGHKT
    
  2. Example 2

    Input
    10 10 10 10 10
    3
    1 1 1 1 1
    9 9 9 8 8
    0 0 0 1 1
    
    Expected output
    457H
    CGHKT
    27H
    GK
    07H
    NULL