## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# Triplets Min CodeChef Solution July 2023

## Problem

You are given an integer array $�$ of size $�$.
triplet array is defined as the collection of $\mathrm{min}\left({�}_{�},{�}_{�},{�}_{�}\right)$ for all triplets $\left(�,�,�\right)$, where $1\le �<�<�\le �$.

You are given $�$ queries of the following type:

• Given an integer $�$, return the value of ${�}^{�ℎ}$ smallest element in the triplet array.

### Input Format

• The first line of input will contain a single integer $�$, denoting the number of test cases.
• Each test case consists of multiple lines of input.
• The first line of each test case contains two space-separated integers $�$ and $�$ — the size of array $�$ and the number of queries, respectively.
• The second line of each test case contains $�$ space-separated integers ${�}_{1},{�}_{2},\dots ,{�}_{�}$.
• The following $�$ lines describe the queries. Each of these lines contain a single positive integer $�$.

### Output Format

For each query, print a single line containing the ${�}^{�ℎ}$ smallest element in the triplet array.

### Explanation:

Test case 1: Here, all elements of triplet array are equal to $3$.

Test case 2: The sorted triplet array is $\left[1,1,1,2\right]$.