#P1948B. Array Fix

Array Fix

Description

You are given an integer array $a$ of length $n$.

You can perform the following operation any number of times (possibly zero): take any element of the array $a$, which is at least $10$, 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 $3$-rd element of the array $[12, 3, 45, 67]$, then the array becomes $[12, 3, 4, 5, 67]$.
  • if we apply this operation to the $2$-nd element of the array $[2, 10]$, then the array becomes $[2, 1, 0]$.

Your task is to determine whether it is possible to make $a$ 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 $a$ in such a way that $a_1 \le a_2 \le \dots \le a_k$, where $k$ is the current length of the array $a$.

deepl翻译

给你一个长度为 nn 的整数数组 aa

你可以执行以下操作任意多次(可能为零):取数组 aa 中至少是 1010 的任意元素,删除它,然后在相同位置插入该元素包含的数字,按它们在该元素中出现的顺序排列。

例如

  • 如果我们对数组 [12,3,45,67][12, 3, 45, 67] 中的 33 /-rd元素执行此操作,那么数组就变成了 [12,3,4,5,67][12, 3, 4, 5, 67]
  • 如果我们对数组 [2,10][2, 10] 中的 22 /-nd 元素执行此操作,那么数组就变成了 [2,1,0][2, 1, 0]

你的任务是确定是否有可能使用上述操作**任意次数(可能是零)**使 aa 以非降序排序。换句话说,你必须确定是否有可能将数组 aa 转换为 a1a2aka_1 \le a_2 \le \dots \le a_k ,其中 kk 是数组 aa 的当前长度。

Input

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

Each test case consists of two lines:

  • the first line contains a single integer $n$ ($2 \le n \le 50$).
  • the second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 99$).

Output

For each test case, print YES if it is possible to make $a$ 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.

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

Note

In the first example, you can split the first element, then the array becomes $[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.