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 maxn = 5e5 + 10, lgn = 19, N = 1 << 19;
int n, q, beg[maxn], l[maxn], r[maxn], ans[maxn][2], sa[maxn], h[maxn][lgn],
    rnk[maxn], len[maxn], ord[maxn], seg[(N << 1) | 10], LOG[maxn];
char s[maxn], t[maxn];
void SA() {
  static int freq[maxn], mx;
  static pair<pair<int, int>, int> p[maxn], q[maxn];
  memset(freq, 0, sizeof freq);
  for (int i = 1; i <= n; ++i) freq[s[i]] = 1;
  for (int i = 1; i < maxn; ++i) freq[i] += freq[i - 1];
  mx = freq[maxn - 1];
  for (int i = 1; i <= n; ++i) rnk[i] = freq[s[i]];
  for (int l = 1; mx < n; l <<= 1) {
    memset(freq, 0, sizeof freq);
    for (int i = 1; i <= n; ++i)
      p[i] = make_pair(make_pair(rnk[i], (i + l <= n ? rnk[i + l] : 0)), i),
      ++freq[p[i].first.second + 1];
    for (int i = 1; i < maxn; ++i) freq[i] += freq[i - 1];
    for (int i = 1; i <= n; ++i) q[++freq[p[i].first.second]] = p[i];
    memset(freq, 0, sizeof freq);
    for (int i = 1; i <= n; ++i) ++freq[q[i].first.first + 1];
    for (int i = 1; i < maxn; ++i) freq[i] += freq[i - 1];
    for (int i = 1; i <= n; ++i) p[++freq[q[i].first.first]] = q[i];
    mx = 0;
    for (int i = 1; i <= n; ++i) {
      if (i == 1 || p[i].first != p[i - 1].first) ++mx;
      rnk[p[i].second] = mx;
    }
  }
  rnk[n + 1] = 0;
  for (int i = 1; i <= n + 1; ++i) sa[rnk[i]] = i;
  for (int i = 1, k = 0; i <= n; ++i) {
    int j = sa[rnk[i] - 1];
    if (k) --k;
    while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) ++k;
    h[rnk[i]][0] = k;
  }
  for (int lg = 1; lg < lgn; ++lg) {
    int l = 1 << lg - 1;
    for (int i = 1; i + l <= n; ++i)
      h[i][lg] = min(h[i][lg - 1], h[i + l][lg - 1]);
  }
  return;
}
void M(int i, int x) {
  for (i |= N; i; i >>= 1) seg[i] = min(seg[i], x);
  return;
}
int Q(int s, int t) {
  int x = maxn;
  for (s |= N, t |= N, --s, ++t; s ^ t ^ 1; s >>= 1, t >>= 1) {
    if (~s & 1) x = min(x, seg[s ^ 1]);
    if (t & 1) x = min(x, seg[t ^ 1]);
  }
  return x;
}
int hQ(int l, int r) {
  if (l == r) return h[l][0];
  int lg = LOG[r - l + 1];
  return min(h[l][lg], h[r - (1 << lg) + 1][lg]);
}
int lcp(int i, int j) {
  i = rnk[i];
  j = rnk[j];
  if (i < j)
    return hQ(i + 1, j);
  else
    return hQ(j + 1, i);
}
int main() {
  for (int i = 2; i < maxn; ++i) LOG[i] = LOG[i >> 1] + 1;
  for (int i = 1; i < ((N << 1) | 10); ++i) seg[i] = maxn;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  s[++n] = '$';
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", l + i, r + i);
    scanf("%s", t);
    beg[i] = n + 1;
    int &j = len[i];
    for (j = 0; t[j]; ++j) s[++n] = t[j];
    s[++n] = '$';
    ord[i] = i;
  }
  SA();
  sort(ord + 1, ord + q + 1,
       [&](int i, int j) { return rnk[beg[i]] > rnk[beg[j]]; });
  for (int ii = 1, lst = n + 1; ii <= q; ++ii) {
    int i = ord[ii], p = rnk[beg[i]];
    if (p == n) {
      ans[i][0] = -1;
      continue;
    }
    while (lst > p) --lst, M(sa[lst], lst);
    int len = min(h[p + 1][0], ::len[i]), j;
    if (::r[i] - len >= ::l[i]) {
      j = Q(::l[i], ::r[i] - len);
      if (j <= n) {
        ans[i][0] = sa[j];
        ans[i][1] = lcp(ans[i][0], beg[i]) + 1;
      }
    }
    for (int j = max(::r[i] - len + 1, ::l[i]); j <= ::r[i]; ++j) {
      if (rnk[j] > p) {
        int LCP = lcp(j, beg[i]);
        if (j + LCP <= ::r[i]) {
          if (!ans[i][0] || rnk[ans[i][0]] > rnk[j])
            ans[i][0] = j, ans[i][1] = LCP + 1;
        }
      }
    }
    if (!ans[i][0]) ans[i][0] = -1;
  }
  for (int i = 1; i <= q; ++i) {
    if (!~ans[i][0])
      puts("-1");
    else {
      for (int j = 0; j < ans[i][1]; ++j) putchar(s[ans[i][0] + j]);
      putchar('\n');
    }
  }
  return 0;
}