Nowadays Babul is solving problems on sub-sequence. He is struck with a problem in which he has to find the longest sub-sequence in an array A of size N such that for all (i,j) where i!=j either A[i] divides A[j] or vice versa. If no such sub-sequence exists then print -1. Help him to accomplish this task.

**Constraints : **

1<=T<=100

2<=N<=1000

1<=A[i]<=1000

**Input:**

The First line contains T no. of test cases.

Each Test case is of two lines.

The First line contains N size of the array.

Next line contains N-Space separated integers, denoting elements of an array.

**Output:**

For each T print the size of the** longest sub-sequence** satisfying the above criteria.

**Example:**

**Input:**

2

5

5 3 1 4 7

6

2 4 6 1 3 11

**Output:**

2

3

**Explanation:**

First Test Case :

Longest Sub Sequence are {5,1} , {4,1}, {3,1} etc. so size is 2.

Second Test Case :

Longest Sub Sequence are {1, 2, 6}, {1, 3, 6} so size is 3.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

the_coder95 | 465 |

thanuvinu94 | 384 |

ShivayLamba | 256 |

adityasuman2025 | 249 |

PrakharBansal1 | 236 |

the_coder95 | 1691 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 1060 |

samay_kam_hai | 724 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.