For each test case, output a single line with a single integer, the answer.
Hint
In the first test case, one of the optimal plans is: Set the traffic light to green in time period $[0,2] \cup [3,4] \cup [5,6]$, and let $w=\{1,2,3,2,3,4\}$. Therefore the answer is $3$.
In the second test case, one of the optimal plans is: Set the traffic light to green in time period $[0,3] \cup [5,6]$, and let $w = \{1,3,2,3,5,3\}$. Therefore the answer is $5$.
In the third test case, one of the optimal plans is: Set the traffic light to green in time period $[0,4]$, and let $w=\{1,4,2,4,3,4\}$. Therefore the answer is $6$.