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;
int n, Rank[1010000], SA[1010000], ord[1010000], C[1010000], ord1[1010000],
    ord2[1010000], LCP[1010000][21], B[1010000], m, L, MM[1048576],
    Res[201000][2], IT[1048576 + 1048576];
char p[1010000];
int BE[201000];
struct AA {
  int a, b;
} w[1010000];
struct UU {
  int b, e, s, l, num, len;
  bool operator<(const UU &p) const { return s < p.s; }
} U[1010000];
int Get(int b, int e) {
  if (b > e) swap(b, e);
  int l = e - b;
  int t = MM[l];
  return min(LCP[b][t], LCP[e - (1 << t)][t]);
}
void Suffix_Array(int n) {
  int i, L = 1, j;
  for (i = 0; i < n; i++) {
    w[i].a = p[i];
    w[i].b = p[i + 1];
  }
  int M = max(n, 200);
  while (1) {
    for (i = 0; i <= M; i++) C[i] = 0;
    for (i = 0; i < n; i++) C[w[i].b]++;
    for (i = 1; i <= M; i++) C[i] += C[i - 1];
    for (i = 0; i < n; i++) ord1[--C[w[i].b]] = i;
    for (i = 0; i <= M; i++) C[i] = 0;
    for (i = 0; i < n; i++) C[w[i].a]++;
    for (i = 1; i <= M; i++) C[i] += C[i - 1];
    for (i = n - 1; i >= 0; i--) ord2[--C[w[ord1[i]].a]] = ord1[i];
    int cnt = 0;
    for (i = 0; i < n; i++) {
      if (i == 0 || w[ord2[i]].a != w[ord2[i - 1]].a ||
          w[ord2[i]].b != w[ord2[i - 1]].b) {
        cnt++;
      }
      Rank[ord2[i]] = cnt;
    }
    if (cnt == n) break;
    L <<= 1;
    for (i = 0; i < n; i++) {
      w[i].a = Rank[i];
      if (i + L >= n)
        w[i].b = 0;
      else
        w[i].b = Rank[i + L];
    }
  }
  for (i = 0; i < n; i++) SA[Rank[i]] = i;
  int t = 0;
  for (i = 0; i < n; i++) {
    int x = Rank[i];
    if (t) t--;
    if (x == n) continue;
    int y = SA[x + 1];
    while (p[i + t] == p[y + t]) t++;
    LCP[x][0] = t;
  }
  for (i = 0; i < 20; i++) {
    for (j = 1; j <= (n - (1 << i)); j++) {
      LCP[j][i + 1] = min(LCP[j][i], LCP[j + (1 << i)][i]);
    }
  }
}
struct Query {
  int b, e;
} Q[201000];
int Len[201000];
int Calc(int a, int l) {
  int b = a + 1, e = L, r = L + 1, mid;
  while (b <= e) {
    mid = (b + e) >> 1;
    if (Get(a, mid) <= l) {
      r = mid;
      e = mid - 1;
    } else
      b = mid + 1;
  }
  return r;
}
int Calc2(int a, int l) {
  int b = a + 1, e = L, r = a, mid;
  while (b <= e) {
    mid = (b + e) >> 1;
    if (Get(a, mid) >= l) {
      r = mid;
      b = mid + 1;
    } else
      e = mid - 1;
  }
  return r;
}
void Put(int a, int b) {
  a += 1048576;
  IT[a] = b;
  while (a != 1) {
    a >>= 1;
    IT[a] = min(IT[a * 2], IT[a * 2 + 1]);
  }
}
int ppv;
int Min(int b, int e) {
  b += 1048576, e += 1048576;
  int r = 2e9, pv = 0;
  while (b <= e) {
    if (r > IT[b]) r = IT[b], pv = b;
    if (r > IT[e]) r = IT[e], pv = e;
    b = (b + 1) >> 1, e = (e - 1) >> 1;
  }
  while (pv < 1048576) {
    pv *= 2;
    if (IT[pv] != r) pv++;
  }
  pv -= 1048576;
  ppv = pv;
  return r;
}
int main() {
  int i, j, pv = 0;
  for (i = 1; i < 1048576 + 1048576; i++) IT[i] = 1e9;
  for (i = 1; i < 1048576; i++) {
    while ((1 << (pv + 1)) <= i) pv++;
    MM[i] = pv;
  }
  scanf("%s", p);
  for (i = 0; p[i]; i++)
    ;
  n = i;
  L = n;
  p[L] = 0;
  L++;
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    Res[i][0] = 0;
    Res[i][1] = -1;
    scanf("%d%d", &Q[i].b, &Q[i].e);
    Q[i].b--, Q[i].e--;
    BE[i] = L;
    scanf("%s", p + BE[i]);
    for (j = L; p[j]; j++)
      ;
    Len[i] = j - BE[i];
    L = j;
    p[L] = 0;
    L++;
  }
  Suffix_Array(L);
  int cnt = 0;
  for (i = 1; i <= m; i++) {
    int pv = BE[i], l = Len[i];
    int b = Q[i].b, e = Q[i].e;
    for (j = l; j >= 0; j--) {
      int t = Calc(Rank[pv], j);
      int t2 = Calc2(Rank[pv], j);
      if (t == L + 1 || t > t2) continue;
      if (b > e - j) continue;
      U[cnt++] = {b, e - j, t, t2, i, j + 1};
    }
  }
  sort(U, U + cnt);
  pv = L;
  for (i = cnt - 1; i >= 0; i--) {
    while (U[i].s <= pv) {
      Put(SA[pv], pv);
      pv--;
    }
    if (Min(U[i].b, U[i].e) > U[i].l) continue;
    int x = U[i].num;
    if (Res[x][1] - Res[x][0] + 1 < U[i].len) {
      Res[x][0] = ppv;
      Res[x][1] = ppv + U[i].len - 1;
    }
  }
  for (i = 1; i <= m; i++) {
    if (Res[i][1] == -1)
      puts("-1");
    else {
      for (j = Res[i][0]; j <= Res[i][1]; j++) printf("%c", p[j]);
      printf("\n");
    }
  }
  return 0;
}