#d2671. 优美的最长上升子序列

优美的最长上升子序列

Beautiful Longest Increasing Subsequence

Problem Description

There are multiple test cases.

For each case you are given an array {A}\{A\} of length NN. Choose an increasing subsequence from it whose indices (1-based) satisfy

i1∣i2∣i3∣⋯∣ik,i_1\mid i_2\mid i_3\mid\cdots\mid i_k,

where a∣ba\mid b means aa divides bb (aa is a divisor of bb). Find the maximum possible length of such a subsequence.

Input Format

The first line contains an integer TT, the number of test cases that follow.

Each test case contains two lines: the first line contains an integer NN; the next line contains NN integers, representing the array {A}\{A\}.

Output Format

For each test case, output one integer on a line, the length of the longest "beautiful" increasing subsequence that can be chosen.

Sample Input

4
4
1 4 6 7
2
2 2
10
1 2 3 4 5 6 7 8 9 10
10
10 9 8 6 5 2 3 1 2 1

Sample Output

3
1
4
1

Sample Explanation

  • In the first case, a valid beautiful LIS is {A1,A2,A4}={1,4,7}\{A_1, A_2, A_4\} = \{1, 4, 7\}.
  • In the third case, we may choose {A1,A2,A4,A8}={1,2,4,8}\{A_1, A_2, A_4, A_8\} = \{1, 2, 4, 8\}.
  • In the fourth case, the longest beautiful LIS has length 11.

Constraints

  • 1≤T≤1001\le T\le 100
  • 1≤N≤1061\le N\le 10^6, and ∑i=1TNi≤106\sum_{i=1}^{T} N_i\le 10^6
  • 1≤Ai≤1091\le A_i\le 10^9