Luca has a cypher made up of a sequence of n wheels, each with a digit ai written on it. On the i-th wheel, he made bi moves. Each move is one of two types:
Solution – CLICK HERE
- up move (denoted by U): it increases the i-th digit by 11. After applying the up move on 99, it becomes 00.
- down move (denoted by D): it decreases the i-th digit by 11. After applying the down move on 00, it becomes 99.
Cypher solution codeforces

Cypher solution codeforces
The first line contains a single integer t (1≤≤1001≤t≤100) — the number of test cases.
The first line of each test case contains a single integer n (1≤≤1001≤n≤100) — the number of wheels.
The second line contains n integers ai (0≤≤90≤ai≤9) — the digit shown on the i-th wheel after all moves have been performed.
Then n lines follow, the i-th of which contains the integer bi (1≤≤101≤bi≤10) and bi characters that are either U or D — the number of moves performed on the i-th wheel, and the moves performed. U and D represent an up move and a down move respectively.
For each test case, output n space-separated digits — the initial sequence of the cypher.
Cypher solution codeforces
3 3 9 3 1 3 DDD 4 UDUU 2 DU 2 0 9 9 DDDDDDDDD 9 UUUUUUUUU 5 0 5 9 8 3 10 UUUUUUUUUU 3 UUD 8 UUDUUDDD 10 UUDUUDUDDU 4 UUUU
2 1 1 9 0 0 4 9 6 9
Cypher solution codeforces
In the first test case, we can prove that initial sequence was [2,1,1][2,1,1]. In that case, the following moves were performed:
- On the first wheel: 2−→1−→0−→92→D1→D0→D9.
- On the second wheel: 1−→2−→1−→2−→31→U2→D1→U2→U3.
- On the third wheel: 1−→0−→11→D0→U1.
The final sequence was [9,3,1][9,3,1], which matches the input.