Problem: Some 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.

  1. A string x consisting of lowercase English letters and integers l and r (1 ≤ l ≤ r ≤ |s|) are chosen. 
  2. Consider all non-empty distinct substrings of the s_l s_{l + 1} … s_r, that is all distinct strings s_i s_{i+1} … s_{j} where l ≤ i ≤ j ≤ r. Among all of them choose all strings that are lexicographically greater than x. 
  3. 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 ≠ b, or there exists such a position i (1 ≤ i ≤ min(|a|, |b|)), such that a_i < b_i and for all j (1 ≤ 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 ≤ |s| ≤ 10^{5}) consisting of lowercase English letters.

The second line contains an integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of strings to select.

Each of the next q lines contains two integers l, r (1 ≤ l ≤ r ≤ |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 ⋅ 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.

  1. 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.
  2. We consider substring "aa". Among its substrings only "aa" is greater than the query string "a". So the answer is "aa".
  3. We consider substring "ba". Out of "b", "a" and "ba" only "ba" is greater than the query string "b", so the answer is "ba".
  4. We consider substring "aa". No substring of "aa" is greater than the query string "aa" so the answer is -1.
  5. 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". 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, L = 20;
char s[N];
int n;
int sa[N], qa[2][N], *rk = qa[0], *tmp = qa[1], cnt[N], h[N], mn_h[L][N], lo[N];
void init_sa() {
  for (int i = 1; i <= n; ++i) sa[i] = i;
  sort(sa + 1, sa + n + 1, [&](int x, int y) { return s[x] < s[y]; });
  rk[sa[1]] = 1;
  for (int i = 2; i <= n; ++i)
    rk[sa[i]] = rk[sa[i - 1]] + (s[sa[i]] != s[sa[i - 1]]);
  for (int l = 1; rk[sa[n]] < n; l <<= 1) {
    int top = 0;
    for (int i = n - l + 1; i <= n; ++i) tmp[++top] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > l) tmp[++top] = sa[i] - l;
    int m = rk[sa[n]];
    for (int i = 1; i <= m; ++i) cnt[i] = 0;
    for (int i = 1; i <= n; ++i) ++cnt[rk[i]];
    for (int i = 1; i <= m; ++i) cnt[i] += cnt[i - 1];
    for (int i = n; i >= 1; --i) sa[cnt[rk[tmp[i]]]--] = tmp[i];
    swap(rk, tmp);
    rk[sa[1]] = 1;
    for (int i = 2; i <= n; ++i)
      rk[sa[i]] = rk[sa[i - 1]] + (tmp[sa[i]] != tmp[sa[i - 1]] ||
                                   tmp[sa[i] + l] != tmp[sa[i - 1] + l]);
  }
  int l = 0;
  for (int i = 1; i <= n; ++i) {
    if (l) --l;
    while (s[i + l] == s[sa[rk[i] + 1] + l]) ++l;
    h[rk[i]] = l;
  }
  for (int i = 1; i <= n; ++i) mn_h[0][i] = h[i];
  for (int j = 1; j <= L - 1; ++j)
    for (int i = 1; i <= n - (1 << j) + 1; ++i)
      mn_h[j][i] = min(mn_h[j - 1][i], mn_h[j - 1][i + (1 << j - 1)]);
  lo[0] = -1;
  for (int i = 2; i <= n; ++i) lo[i] = lo[i / 2] + 1;
}
int query_mn_h(int l, int r) {
  int j = lo[r - l + 1];
  return min(mn_h[j][l], mn_h[j][r - (1 << j) + 1]);
}
namespace ZKW {
const int T = N * 3;
int mn[T], d;
void init() {
  for (d = 1; d < n; d <<= 1)
    ;
  d -= 1;
  for (int i = 1; i <= n + d + 1; ++i) mn[i] = N;
}
void add(int i, int x) {
  i += d;
  while (mn[i] > x) {
    mn[i] = x;
    i >>= 1;
  }
}
int query(int i, int x) {
  i += d;
  while (i) {
    if (i % 2 == 0 && mn[i + 1] <= x) {
      ++i;
      while (i <= d) i = i * 2 + (mn[i * 2] > x);
      return i - d;
    }
    i >>= 1;
  }
  return N;
}
};  // namespace ZKW
int m, fir[N], qr[N];
pair<int, int> ans[N];
vector<int> lkq[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    fir[i] = ++n;
    int l;
    scanf("%d%d%s", &l, qr + i, s + n);
    lkq[l].push_back(i);
    n += strlen(s + n);
    s[n] = 1;
  }
  fir[m + 1] = n + 1;
  init_sa();
  ZKW::init();
  for (int l = fir[1] - 1; l >= 1; --l) {
    ZKW::add(rk[l], l);
    for (auto i : lkq[l]) {
      int r = qr[i];
      int x = rk[fir[i]], len = fir[i + 1] - fir[i] - 1;
      for (int lcp = len; lcp >= 0; --lcp) {
        int x1 = x;
        for (int j = L - 1; j >= 0; --j)
          if (mn_h[j][x1] > lcp) x1 += 1 << j;
        int j = ZKW::query(x1, r - lcp);
        if (j <= n && query_mn_h(x, j - 1) == lcp) {
          ans[i].first = sa[j];
          ans[i].second = ans[i].first + lcp;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= m; ++i)
    if (!ans[i].second)
      puts("-1");
    else {
      for (int j = ans[i].first; j <= ans[i].second; ++j) printf("%c", s[j]);
      puts("");
    }
}