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 mod = 1e9 + 7;
const int maxm = 1e5 + 10;
char s[maxm], str[2 * maxm];
int rt[maxm * 2], c[maxm * 2], q[maxm * 2], rig[maxm * 2], maxlen[maxm * 2],
    trans[maxm * 2][27], link[maxm * 2];
int siz = 1, last = 1;
int cnt;
stack<char> ans, ans1;
int aa[maxm * 2];
struct node {
  int ls, rs, flag;
} tree[50 * maxm];
int extend(int id) {
  int cur = ++siz;
  int p;
  maxlen[cur] = maxlen[last] + 1;
  for (p = last; p && !trans[p][id]; p = link[p]) trans[p][id] = cur;
  if (!p)
    link[cur] = 1;
  else {
    int q = trans[p][id];
    if (maxlen[q] == maxlen[p] + 1)
      link[cur] = q;
    else {
      int clone = ++siz;
      maxlen[clone] = maxlen[p] + 1;
      memcpy(trans[clone], trans[q], sizeof(trans[q]));
      link[clone] = link[q];
      for (; p && trans[p][id] == q; p = link[p]) trans[p][id] = clone;
      link[cur] = link[q] = clone;
    }
  }
  last = cur;
  return last;
}
void pushup(int rt) {
  tree[rt].flag += tree[tree[rt].ls].flag + tree[tree[rt].rs].flag;
  tree[rt].flag = min(tree[rt].flag, 1);
}
void merge(int &a, int b, int l, int r) {
  if (!b) return;
  if (!a) {
    a = b;
    return;
  }
  tree[++cnt] = tree[a];
  a = cnt;
  if (l == r) {
    tree[a].flag += tree[b].flag;
    tree[a].flag = min(tree[a].flag, 1);
    return;
  }
  int mid = l + r >> 1;
  merge(tree[a].ls, tree[b].ls, l, mid);
  merge(tree[a].rs, tree[b].rs, mid + 1, r);
  pushup(a);
  return;
}
void update(int &rt, int l, int r, int pos) {
  if (!rt) rt = ++cnt;
  if (l == r) {
    tree[rt].flag = 1;
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    update(tree[rt].ls, l, mid, pos);
  else
    update(tree[rt].rs, mid + 1, r, pos);
  pushup(rt);
}
int query(int rt, int l, int r, int L, int R) {
  if (!rt) return 0;
  if (L <= l && r <= R) {
    return tree[rt].flag;
  }
  int m = l + r >> 1;
  int res = 0;
  if (L <= m) res = max(res, query(tree[rt].ls, l, m, L, R));
  if (R > m) res = max(res, query(tree[rt].rs, m + 1, r, L, R));
  return res;
}
void radix() {
  for (int i = 1; i <= siz; i++) c[maxlen[i]]++;
  for (int i = 1; i <= siz; i++) c[i] += c[i - 1];
  for (int i = siz; i; i--) q[c[maxlen[i]]--] = i;
}
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    int sta = extend(s[i] - 'a');
    update(rt[sta], 1, n, i);
  }
  radix();
  for (int i = siz; i; i--) {
    int u = q[i];
    if (link[u] > 1) merge(rt[link[u]], rt[u], 1, n);
  }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    while (!ans.empty()) {
      ans.pop();
    }
    while (!ans1.empty()) ans1.pop();
    int l, r;
    scanf("%d%d", &l, &r);
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    int now = 1;
    int temp = 1;
    str[len + 1] = 0;
    aa[0] = 1;
    while ((temp <= len) && (trans[now][str[temp] - 'a'])) {
      ans.push(str[temp]);
      now = trans[now][str[temp] - 'a'];
      aa[temp] = now;
      temp++;
    }
    int ok = 0;
    for (int i = temp - 1; i >= 0; i--) {
      if (r - l + 1 < i + 1) {
        if (!ans.empty()) ans.pop();
        continue;
      }
      for (char ch = 'a'; ch <= 'z'; ch++) {
        if ((ch > str[i + 1]) && (trans[aa[i]][ch - 'a'])) {
          int res = query(rt[trans[aa[i]][ch - 'a']], 1, n, l + i, r);
          if (res) {
            ans.push(ch);
            ok = 1;
            break;
          }
        }
      }
      if (ok) break;
      if (!ans.empty()) ans.pop();
    }
    if (ok) {
      while (!ans.empty()) {
        char ch = ans.top();
        ans.pop();
        ans1.push(ch);
      }
      while (!ans1.empty()) {
        char ch = ans1.top();
        ans1.pop();
        printf("%c", ch);
      }
      printf("\n");
    } else
      printf("-1\n");
  }
  return 0;
}