Given an array **arr[]** of **N** elements. Perform **K** right circular rotations on given ranges [**L..R**]. After performing these rotations, we need to find element at a given index **X**.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of three lines. First line of each test case contains three integers **N**, **X** and **K**. Second line contains **N** space separated array elements and next line contains **K** ranges [**L, R**] (space seperated) on which we have to rotate the array in right circular manner.

**Output:**

For each test case, print the **array[X]** (0-based indexing)element after K rotations in new line.

**Constraints:**

1 <= T <= 500

2 <= N <= 10^{5}

1 <= arr[] <= 10^{5}

1 <= K <= 10^{5}

X < N

0 <= L <= R

**Example:
Input:**

2

5 1 2

1 2 3 4 5

0 2 0 3

3 2 1

1 2 3

0 1

**Output:**

3

3

**Explanation:
Testcase 1:** Rotating the elements in range 0-2 and 0-3, we have array as 4 3 1 2 5. Element at first position is 3.

Author: arun03

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 | 102 |

PiyushPandey4 | 100 |

codefundo | 95 |

kya_bolti_public | 93 |

masterishaan19 | 74 |

PiyushPandey4 | 916 |

john_wick | 765 |

ASWATHAMA | 565 |

UsfShilpa | 556 |

akhyasharma01 | 547 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.