Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

H. Security

time limit per test

4 secondsmemory limit per test

512 megabytesinput

standard inputoutput

standard outputSome programming website is establishing a secure communication protocol. For security reasons, they want to choose several more or less random strings.

Initially, they have a string $$$s$$$ consisting of lowercase English letters. Now they want to choose $$$q$$$ strings using the following steps, and you are to help them.

- A string $$$x$$$ consisting of lowercase English letters and integers $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq |s|$$$) are chosen.
- Consider all non-empty distinct substrings of the $$$s_l s_{l + 1} \ldots s_r$$$, that is all distinct strings $$$s_i s_{i+1} \ldots s_{j}$$$ where $$$l \le i \le j \le r$$$. Among all of them choose all strings that are lexicographically greater than $$$x$$$.
- If there are no such strings, you should print $$$-1$$$. Otherwise print the lexicographically smallest among them.

String $$$a$$$ is lexicographically less than string $$$b$$$, if either $$$a$$$ is a prefix of $$$b$$$ and $$$a \ne b$$$, or there exists such a position $$$i$$$ ($$$1 \le i \le min(|a|, |b|)$$$), such that $$$a_i < b_i$$$ and for all $$$j$$$ ($$$1 \le j < i$$$) $$$a_j = b_j$$$. Here $$$|a|$$$ denotes the length of the string $$$a$$$.

Input

The first line of input contains a non-empty string $$$s$$$ ($$$1 \leq |s| \leq 10^{5}$$$) consisting of lowercase English letters.

The second line contains an integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of strings to select.

Each of the next $$$q$$$ lines contains two integers $$$l$$$, $$$r$$$ ($$$1 \leq l \leq r \leq |s|$$$) and a non-empty string $$$x$$$ consisting of lowercase English letters. The total length of strings $$$x$$$ for all queries does not exceed $$$2 \cdot 10^{5}$$$.

Output

Output $$$q$$$ lines, each of them should contain the desired string or $$$-1$$$, if there is no such string.

Examples

Input

baa

5

1 2 ba

2 3 a

1 2 b

2 3 aa

1 3 b

Output

-1

aa

ba

-1

ba

Input

bacb

4

1 2 ba

2 3 ac

1 3 ac

3 4 c

Output

-1

c

b

cb

Input

bba

1

1 1 b

Output

-1

Note

Consider the first example.

The string $$$s$$$ is "baa". The queries are as follows.

- We consider the substring $$$s_1 s_2$$$ that is "ba". It has substrings "b", "a" and "ba", since none of them is greater than the query string "ba", the answer is $$$-1$$$.
- We consider substring "aa". Among its substrings only "aa" is greater than the query string "a". So the answer is "aa".
- We consider substring "ba". Out of "b", "a" and "ba" only "ba" is greater than the query string "b", so the answer is "ba".
- We consider substring "aa". No substring of "aa" is greater than the query string "aa" so the answer is $$$-1$$$.
- We consider substring "baa" and it has (among others) substrings "ba", "baa" which are greater than the query string "b". Since "ba" is lexicographically smaller than "baa", the answer is "ba".

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/22/2019 16:21:01 (d1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|