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;
}
相关推荐
黑不溜秋的5 小时前
C++ 设计模式 - 策略模式
c++·设计模式·策略模式
Dream it possible!7 小时前
LeetCode 热题 100_在排序数组中查找元素的第一个和最后一个位置(65_34_中等_C++)(二分查找)(一次二分查找+挨个搜索;两次二分查找)
c++·算法·leetcode
柠石榴7 小时前
【练习】【回溯No.1】力扣 77. 组合
c++·算法·leetcode·回溯
王老师青少年编程7 小时前
【GESP C++八级考试考点详细解读】
数据结构·c++·算法·gesp·csp·信奥赛
澄澈天空8 小时前
C++ MFC添加RichEditControl控件后,程序启动失败
c++·mfc
Lzc7749 小时前
C++初阶——简单实现vector
c++·简单实现vector
一个小白110 小时前
C++——list模拟实现
开发语言·c++
程序员老舅10 小时前
C++ Qt项目教程:WebServer网络测试工具
c++·qt·测试工具·webserver·qt项目·qt项目实战
靡不有初11110 小时前
CCF-CSP第18次认证第一题——报数【两个与string相关的函数的使用】
c++·学习·ccfcsp
cookies_s_s12 小时前
Linux--进程(进程虚拟地址空间、页表、进程控制、实现简易shell)
linux·运维·服务器·数据结构·c++·算法·哈希算法