electicode
HomeCoursesResourcesProblemsNational OlympiadContestsLeaderboard
...

Break into digits

Time Limit: 1000msMemory Limit: 256MB
View Submissions

Problem Description

Given an array of integers aaa of length nnn.

It is allowed to perform the following operation any number of times (including zero):
choose an element of the array that is at least 101010, remove it, and replace it with the digits it consists of, preserving the order of the digits and the position in the array.

For example, the number 454545 can be replaced with (4,5)(4, 5)(4,5), and the number 101010 can be replaced with (1,0)(1, 0)(1,0).

You need to determine whether it is possible to obtain an array sorted in non-decreasing order, that is, a1≤a2≤⋯≤ak,a_1 \le a_2 \le \dots \le a_k,a1​≤a2​≤⋯≤ak​, where is the current length of the array.

Input

In the first line, an integer ttt (1≤t≤10001 \le t \le 10001≤t≤1000) is given — the number of input data sets.

For each set:

  • in the first line, an integer nnn (2≤n≤1052 \le n \le 10^52≤n≤105) is given;
  • in the second line, an array a1,a2,…,ana_1, a_2, \dots, a_na1​,a ().

The sum of nnn across all tests does not exceed 10510^5105.

Output

For each data set, output YES if it is possible to obtain a non-decreasing array, and NO otherwise.

The case of letters in the answer does not matter.

Scoring System

GroupAdditional ConstraintsPointsRequired Groups
0examples0—
1ai≤9a_i \le 9ai​≤910—
210≤

Examples

Example 1
Input
3
4
12 3 45 67
3
12 28 5
2
0 0
Output
Yes
No
Yes

© 2026 Electicode. All rights reserved.

kk
k
2​
,
…
,
an​
0≤ai≤1090 \le a_i \le 10^90≤ai​≤109
ai≤9910 \le a_i \le 99
10≤ai​≤99
30
—
4no additional constraints600, 1, 2