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;
inline int read() {
  int x = 0, y = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') y = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return y ? -x : x;
}
int h[400005], root[400005], ls[400005 << 5], rs[400005 << 5], all, num;
int son[400005][26], len[400005], fa[400005], nex[400005], last = 1, cnt = 1, n,
                                                           N;
char s[400005];
struct edge {
  int pre, to;
} e[400005];
inline void add(int from, int to) {
  e[++num].pre = h[from], h[from] = num, e[num].to = to;
}
void modify(int poi, int l, int r, int &node) {
  node = ++all;
  if (l == r) return;
  int mid = l + r >> 1;
  if (poi <= mid)
    modify(poi, l, mid, ls[node]);
  else
    modify(poi, mid + 1, r, rs[node]);
}
int merge(int x, int y, int l, int r) {
  if (!x || !y || l == r) return x | y;
  int ne = ++all, mid = l + r >> 1;
  ls[ne] = merge(ls[x], ls[y], l, mid);
  rs[ne] = merge(rs[x], rs[y], mid + 1, r);
  return ne;
}
bool ask(int L, int R, int l, int r, int node) {
  if (!node) return 0;
  if (L <= l && R >= r) return 1;
  int mid = l + r >> 1;
  if (L <= mid && ask(L, R, l, mid, ls[node])) return 1;
  if (R > mid && ask(L, R, mid + 1, r, rs[node])) return 1;
  return 0;
}
void insert(int c) {
  int p = last, ne = last = ++cnt;
  modify(len[ne] = len[p] + 1, 1, N, root[ne]);
  while (p && !son[p][c]) son[p][c] = ne, p = fa[p];
  if (!p)
    fa[ne] = 1;
  else {
    int q = son[p][c];
    if (len[q] == len[p] + 1)
      fa[ne] = q;
    else {
      int sp = ++cnt;
      memcpy(son[sp], son[q], sizeof son[q]);
      fa[sp] = fa[q], len[sp] = len[p] + 1, fa[q] = fa[ne] = sp;
      while (p && son[p][c] == q) son[p][c] = sp, p = fa[p];
    }
  }
}
void dfs(int node = 1) {
  int x;
  for (register int i = h[node]; i; i = e[i].pre)
    x = e[i].to, dfs(x), root[node] = merge(root[node], root[x], 1, N);
}
int main() {
  scanf("%s", s + 1), N = strlen(s + 1);
  for (register int i = 1; i <= N; ++i) insert(s[i] - 'a');
  for (register int i = 2; i <= cnt; ++i) add(fa[i], i);
  dfs();
  int m = read(), l, r, node, x, i;
  while (m--) {
    l = read(), r = read(), node = 1;
    scanf("%s", s + 1), n = strlen(s + 1);
    for (i = 1;; ++i) {
      nex[i] = -1;
      for (register int j = max(s[i] - 'a' + 1, 0); j < 26; ++j) {
        x = son[node][j];
        if (x && ask(l + i - 1, r, 1, N, root[x])) {
          nex[i] = j;
          break;
        }
      }
      x = son[node][s[i] - 'a'];
      if (!x || i == n + 1 || !ask(l + i - 1, r, 1, N, root[x])) break;
      node = x;
    }
    while (i && nex[i] == -1) --i;
    if (!i)
      puts("-1");
    else {
      for (register int j = 1; j < i; ++j) putchar(s[j]);
      putchar(nex[i] + 'a');
      puts("");
    }
  }
}