Cypher密码

time limit per test

1 second

memory limit per test

256 megabytes

Luca has a cypher made up of a sequence of nn wheels, each with a digit aiai written on it. On the ii-th wheel, he made bibi moves. Each move is one of two types:

  • up move (denoted by UU): it increases the ii-th digit by 11. After applying the up move on 99, it becomes 00.
  • down move (denoted by DD): it decreases the ii-th digit by 11. After applying the down move on 00, it becomes 99.

Example for n=4n=4. The current sequence is 0 0 0 0.

Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.

Input

The first line contains a single integer tt (1≤t≤1001≤t≤100) --- the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) --- the number of wheels.

The second line contains nn integers aiai (0≤ai≤90≤ai≤9) --- the digit shown on the ii-th wheel after all moves have been performed.

Then nn lines follow, the ii-th of which contains the integer bibi (1≤bi≤101≤bi≤10) and bibi characters that are either UU or DD --- the number of moves performed on the ii-th wheel, and the moves performed. UU and DD represent an up move and a down move respectively.

Output

For each test case, output nn space-separated digits --- the initial sequence of the cypher.

Example

Input

Copy

复制代码

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

Output

Copy

复制代码
2 1 1 
9 0 
0 4 9 6 9 

Note

In the first test case, we can prove that initial sequence was 2,1,12,1,1. In that case, the following moves were performed:

  • On the first wheel: 2→D1→D0→D92→D1→D0→D9.
  • On the second wheel: 1→U2→D1→U2→U31→U2→D1→U2→U3.
  • On the third wheel: 1→D0→U11→D0→U1.

The final sequence was 9,3,19,3,1, which matches the input.

每次测试时间限制 1 秒

每次测试内存限制 256 兆字节

Luca 有一个由 n 个转轮组成的密码,每个转轮上都写有一个数字 ai。在第 i 个转轮上,他进行了 bi

移动。每次移动都有两种类型:

向上移动(用 U 表示):将第 i 个数字增加 1。在 9 上应用向上移动后,它变为 0。

向下移动(用 D 表示):将第 i 个数字减少 1。在 0 上应用向下移动后,它变为 9。

n=4 的示例。当前序列为 0 0 0 0。

Luca 知道转轮的最终序列以及每个转轮的移动。帮助他找到原始序列并破解密码。

输入

第一行包含一个整数 t

(1≤t≤100

) --- 测试用例的数量。

每个测试用例的第一行包含一个整数 n

(1≤n≤100

) --- 轮子的数量。

第二行包含 n

个整数 ai

(0≤ai≤9

) --- 完成所有移动后第 i 个轮子上显示的数字。

接下来是 n

行,第 i

行包含整数 bi

(1≤bi≤10

) 和 bi

个字符,这些字符要么是 U

要么是 D

--- 在第 i

个轮子上执行的移动次数以及执行的移动。U

和 D

分别代表向上移动和向下移动。

输出

对于每个测试用例,输出 n

个空格分隔的数字 --- 密码的初始序列。

示例

输入副本

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

注意

在第一个测试用例中,我们可以证明初始序列是 2,1,1

。在这种情况下,执行了以下移动:

在第一个轮子上:2→D1→D0→D9

。

在第二个轮子上:1→U2→D1→U2→U3

。

在第三个轮子上:1→D0→U1

。

最终序列是 9,3,1

,与输入相匹配。

代码:

cpp 复制代码
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }

        vector<int> initial(n);
        for (int i = 0; i < n; ++i) {
            int b;
            string moves;
            cin >> b >> moves;

            int current = a[i];

            for (char move : moves) {
                if (move == 'U') {
                    current = (current - 1 + 10) % 10;
                }
                else if (move == 'D') {
                    current = (current + 1) % 10;
                }
            }

            initial[i] = current;
        }

        for (int i = 0; i < n; ++i) {
            cout << initial[i] << " ";
        }
        cout << endl;
    }

    return 0;
}
相关推荐
码客-ygluu5 小时前
X3 LUA 异步分布式微服务集群框架
c++·架构·lua
九英里路7 小时前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
纪念 2298 小时前
C++ 算法基础 (差分)
开发语言·c++·算法
ShineWinsu13 小时前
对于Qt:QTreeWidget常见属性以及QTreeWidgetItem类的解析
开发语言·c++·qt·gui·客户端·多叉树·qtreewidget
落羽的落羽13 小时前
【C++】C++17的主要特性
linux·服务器·开发语言·c++·算法·机器学习
汉克老师19 小时前
《从C++小白到算法高手:GESP 1—8级成长地图》第一讲:认识GESP——从编程新手到算法探索者
c++·gesp·信息学竞赛·小学生学c++
晴天的雨.99220 小时前
【C++】继承篇
java·开发语言·c++
青少儿编程课堂20 小时前
蓝桥杯青少组图形化 + 全国青少年信息素养大赛 + 电子学会图形化考级:校园大富翁经营闯关解析
c++·python·算法·bfs·信息学竞赛
another heaven20 小时前
【C/C++ 第一次跨越(上):用 C++11/14 停止制造新的旧代码】
c语言·c++·制造
qq_4069810320 小时前
c++ lamda(三)Lambda表达式
java·前端·c++