**Compilation/Execution Result:**

Given an array of n integers which may contain duplicate elements, index of an element of this array is given to us, We need to find the final position of this element ( for which the index is given) in the array after stable sort is applied on the array.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Each test case contains two integers n and idx. Next line contains space separated n elements in the array a[].

**Output:**

Print the index(0 based indexing) of the element after a stable sort operation.

**Constraints:**

1<=T<=200

1<=n<=1000

0<=idx 1<=a[i]<=10000

**Example:
Input:**

1

10 5

3 4 3 5 2 3 4 3 1 5

4

Author: shashwat jain

Shashank_Pathak | 200 |

surbhi_7 | 168 |

yati493 | 167 |

SANJAY5797 | 164 |

dark_knights | 162 |

surbhi_7 | 556 |

Shashank_Pathak | 556 |

dark_knights | 501 |

Infinty | 341 |

Vasudha Gupta | 308 |

akhayrutdinov | 4156 |

sanjay05 | 3597 |

Quandray | 2778 |

Ibrahim Nash | 2475 |

Michael Riegger | 2280 |