CF2164A Sequence Game
Description
Given an integer sequence of length $ n $ denoted as $ a_1,a_2,\ldots,a_n $ and an integer $ x $ .
You can perform the following operation: select two adjacent numbers $ a_i $ and $ a_{i+1} $ and replace them with an integer $ y $ , which satisfies $ \min(a_i,a_{i+1}) \le y \le \max(a_i,a_{i+1}) $ . After the replacement, the original $ a_i $ and $ a_{i+1} $ are removed from the sequence, and the elements are renumbered from $ 1 $ to $ n-1 $ .
For example, for $ a=[1,2,4,5] $ you can select $ a_2=2 $ and $ a_3=4 $ , and replace them with $ 3 $ . After that, $ a $ becomes $ [1,3,5] $ . However, you cannot select $ a_1=1 $ and $ a_2=2 $ and replace them with $ 3 $ (since $ y $ is bigger than $ \max(a_i,a_{i+1}) $ , nor can you select $ a_1=1 $ and $ a_3=4 $ (the selected numbers should be adjacent).
Clearly, after performing $ n-1 $ operations, only one number will remain. The question is whether this final number can be exactly equal to $ x $ .
Input Format
Each test contains multiple test cases. The first line contains the number of test cases $ T $ ( $ 1 \le T \le 500 $ ). The description of the test cases follows.
The first line of each test case contains one integer $ n $ ( $ 1 \le n \le 100 $ ).
The second line of each test case contains $ n $ integers $ a_1,a_2,\ldots,a_n $ ( $ -10^9 \le a_i \le 10^9 $ ).
The third line of each test case contains one integer $ x $ ( $ -10^9 \le x \le 10^9 $ ).
Output Format
For each test case, output "YES" (without quotes) if the final number can be exactly equal to $ x $ , and "NO" otherwise.
You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).
Explanation/Hint
In the first test case, you can first select $ a_2=7 $ and $ a_3=5 $ , and replace them with $ 6 $ . After that, $ a $ becomes $ [2, 6] $ . Now you can select $ a_1=2 $ and $ a_2=6 $ , and replace them with $ 4 $ .
In the second test case, it can be shown that the final number can never be $ 8 $ .