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,1][2,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,1][9,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;
}
相关推荐
梦星辰.8 分钟前
VSCode CUDA C++进行Linux远程开发
linux·c++·vscode
whoarethenext1 小时前
C++ OpenCV 学习路线图
c++·opencv·学习
闻缺陷则喜何志丹1 小时前
【强连通分量 缩点 拓扑排序】P3387 【模板】缩点|普及+
c++·算法·拓扑排序·洛谷·强连通分量·缩点
hutaotaotao2 小时前
c++中的输入输出流(标准IO,文件IO,字符串IO)
c++·io·fstream·sstream·iostream
AL流云。2 小时前
【优选算法】C++滑动窗口
数据结构·c++·算法
qq_429879673 小时前
省略号和可变参数模板
开发语言·c++·算法
CodeWithMe4 小时前
【C/C++】std::vector成员函数清单
开发语言·c++
uyeonashi4 小时前
【QT控件】输入类控件详解
开发语言·c++·qt
zh_xuan8 小时前
c++ 单例模式
开发语言·c++·单例模式
利刃大大10 小时前
【在线五子棋对战】二、websocket && 服务器搭建
服务器·c++·websocket·网络协议·项目