Given a sorted array **arr**[] of size N without duplicates, and given a value **x**. Find the floor of x in given array. Floor of x is defined as the largest element **K** in arr[] such that K is smaller than or equal to x.

**Input:**

First line of input contains number of testcases T. For each testcase, first line of input contains number of elements in the array and element whose floor is to be searched. Last line of input contains array elements.

**Output:**

Output the **index of **floor of x if exists, else print -1.

**Constraints:**

1 ≤ T ≤ 100

1 ≤ N ≤ 10^{7}

1 ≤ arr[i] ≤ 10^{18}

0 ≤ X ≤^{ }arr[n-1]

**Example:
Input:**

3

7 0

1 2 8 10 11 12 19

7 5

1 2 8 10 11 12 19

7 10

1 2 8 10 11 12 19

**Output:**

-1

1

3

**Explanation:**

**Testcase 1:** No element less than 0 is found. So output is "**-1**".

**Testcase 2:** Number less than 5 is **2**, whose index is **1**(0-based indexing).

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.

cs_abhi | 62 |

kya_bolti_public | 56 |

Shubhankar Sharma | 44 |

vermaankush14291 | 42 |

coderquill | 40 |

PiyushPandey4 | 856 |

john_wick | 757 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

UsfShilpa | 536 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.