CCCGuide

Problem J3: Product Codes

2025 · J3 · Original problem · DMOJ

Problem Description

A store has hired the Code Cleaning Crew to help it update all of its product codes.

The original product codes are sequences of letters, positive integers, and negative integers. For example, cG23mH-9s is a product code that contains two uppercase letters, three lowercase letters, one positive integer, and one negative integer.

The new product codes are made by removing all lowercase letters, keeping all uppercase letters in order, and adding all the integers to form one new integer which is placed at the end of the code. For example, the new product code for cG23mH-9s is GH14.

Your job is to take a list of original product codes and determine the new product codes.

Input Specification

The first line of input contains a positive integer, NN, representing the number of original product codes that need to be updated. The following NN lines each contain one original product code.

Each original product code contains at least one uppercase letter, at least one lowercase letter, and at least one integer. Also, a positive integer never immediately follows another integer. This means, for example, that 23 is the integer 2323 instead of the integer 22 followed by the integer 33.

The following table shows how the available 1515 marks are distributed:

MarksDescription
22All the integers are positive and single-digit.
22All the integers are single-digit.
77Any positive integer may be multi-digit.
44Any integer may be multi-digit.

Output Specification

Output the NN new product codes, one per line.

Sample Input 1

1
AbC3c2Cd9

Output for Sample Input 1

ACC14

Explanation of Output for Sample Input 1

For the single original product code, the uppercase letters A, C, and C are kept in order and the sum of the integers is 3+2+9=143+2+9=14.

Sample Input 2

3
Ahkiy-6ebvXCV1
393hhhUHkbs5gh6QpS-9-8
PL12N-2G1234Duytrty8-86tyaYySsDdEe

Output for Sample Input 2

AXCV-5
UHQS387
PLNGDYSDE1166

Explanation of Output for Sample Input 2

For the first original product code, the uppercase letters A, X, C, and V are kept in order and the sum of the integers is −6+1=−5-6+1=-5.

For the second and third original product codes, their uppercase letters are also kept in order and the sums of the integers are 393+5+6−9−8=387393+5+6-9-8=387 and 12−2+1234+8−86=116612-2+1234+8-86=1166 respectively.