CF1948B.Array Fix

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Array Fix

You are given an integer array aa of length nn.

You can perform the following operation any number of times (possibly zero): take any element of the array aa, which is at least 1010, delete it, and instead insert the digits that element consisted of in the same position, in order they appear in that element.

For example:

  • if we apply this operation to the 33-rd element of the array [12,3,45,67][12, 3, 45, 67], then the array becomes [12,3,4,5,67][12, 3, 4, 5, 67].
  • if we apply this operation to the 22-nd element of the array [2,10][2, 10], then the array becomes [2,1,0][2, 1, 0].

Your task is to determine whether it is possible to make aa sorted in non-descending order using the aforementioned operation any number of times (possibly zero). In other words, you have to determine if it is possible to transform the array aa in such a way that a1a2aka_1 \le a_2 \le \dots \le a_k, where kk is the current length of the array aa.

Input

The first line contains a single integer tt (1t1031 \le t \le 10^3) — the number of test cases.

Each test case consists of two lines:

  • the first line contains a single integer nn (2n502 \le n \le 50).
  • the second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ai990 \le a_i \le 99).

Output

For each test case, print YES if it is possible to make aa sorted in non-decreasing order using the aforementioned operation; otherwise, print NO.

You can print each letter in any case. For example, yes, Yes, YeS will all be recognized as a positive answer.

Note

In the first example, you can split the first element, then the array becomes [1,2,3,45,67][1, 2, 3, 45, 67].

In the second example, there is no way to get a sorted array.

In the third example, the array is already sorted.

Samples

3
4
12 3 45 67
3
12 28 5
2
0 0
YES
NO
YES

在线编程 IDE

建议全屏模式获得最佳体验