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.

bruceewayne | 193 |

manvirag982 | 182 |

Core_Ka_Bachha | 180 |

shivam123ahuja | 175 |

Sanjana Singh 1 | 173 |

mr_kksparrow | 433 |

manvirag982 | 398 |

TheHandle | 291 |

rajupraaa1234 | 276 |

Exception_404 | 268 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.