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.

d_Coder00 | 134 |

dungeon_master1299 | 126 |

Astikeysingh | 120 |

rajendrashekhawat063 | 115 |

kaustavbhattachaarya | 111 |

Pulkit__Sharma__ | 646 |

Anirban166 | 531 |

abducodes | 501 |

Found_me | 454 |

Yo_Nehru | 404 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.