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>
const int max_N = (int)2e5 + 21;
const int sigma = 26;
char s[max_N], t[max_N];
int n, q;
namespace SAM {
int tot, rt, last;
int len[max_N], par[max_N], go[max_N][sigma];
int new_node(int L) {
  int x = ++tot;
  memset(go[x], 0, sizeof go[x]);
  par[x] = 0;
  len[x] = L;
  return x;
}
void extend(int c) {
  int p = last;
  int np = last = new_node(len[p] + 1);
  par[np] = rt;
  for (; p && !go[p][c]; p = par[p]) {
    go[p][c] = np;
  }
  if (p) {
    int q = par[np] = go[p][c];
    if (len[q] != len[p] + 1) {
      int nq = ++tot;
      par[nq] = par[q];
      len[nq] = len[p] + 1;
      memcpy(go[nq], go[q], sizeof go[q]);
      par[q] = par[np] = nq;
      for (; p && go[p][c] == q; p = par[p]) {
        go[p][c] = nq;
      }
    }
  }
}
int cnt[max_N], Q[max_N];
void sort(int max_L) {
  for (int i = 0; i < max_L; ++i) {
    cnt[i] = 0;
  }
  for (int i = 1; i <= SAM::tot; ++i) {
    ++cnt[len[i]];
  }
  for (int i = 1; i < max_L; ++i) {
    cnt[i] += cnt[i - 1];
  }
  for (int i = SAM::tot; i; --i) {
    Q[cnt[len[i]]--] = i;
  }
}
void init() {
  tot = 0;
  last = rt = new_node(0);
}
}  // namespace SAM
namespace SegmentTree {
const int max_N = ::max_N * 30;
int tot, sum[max_N], ls[max_N], rs[max_N], rt[max_N];
int new_node(int pos) {
  int l = 1, r = n;
  int x = ++tot;
  sum[x] = 1;
  int y = x;
  while (l < r) {
    if (pos <= ((l + r) >> 1)) {
      ls[x] = ++tot;
      x = ls[x];
      r = ((l + r) >> 1);
    } else {
      rs[x] = ++tot;
      x = rs[x];
      l = ((l + r) >> 1) + 1;
    }
    sum[x] = 1;
  }
  return y;
}
int merge(int x, int y) {
  if (!x || !y) {
    return x + y;
  }
  int z = ++tot;
  sum[z] = sum[x] + sum[y];
  ls[z] = merge(ls[x], ls[y]);
  rs[z] = merge(rs[x], rs[y]);
  return z;
}
int query(int ql, int qr, int x, int l = 1, int r = n) {
  if (!x || ql > qr) {
    return 0;
  }
  if (ql <= l && r <= qr) {
    return sum[x];
  } else {
    int ret = 0;
    if (ql <= ((l + r) >> 1)) {
      ret += query(ql, qr, ls[x], l, ((l + r) >> 1));
    }
    if (qr > ((l + r) >> 1)) {
      ret += query(ql, qr, rs[x], ((l + r) >> 1) + 1, r);
    }
    return ret;
  }
}
int get_right(int x) {
  int l = 1, r = n;
  while (l < r) {
    if (sum[ls[x]]) {
      x = ls[x];
      r = ((l + r) >> 1);
    } else {
      x = rs[x];
      l = ((l + r) >> 1) + 1;
    }
  }
  return l;
}
}  // namespace SegmentTree
int sl[max_N], sr[max_N];
std::vector<int> vec[max_N];
void debug_dfs(int u) {
  for (const int& v : vec[u]) {
    printf("%d-", u);
    for (int i = sl[v]; i < sr[v]; ++i) {
      putchar(s[i - 1]);
    }
    printf("->%d\n", v);
    debug_dfs(v);
  }
}
void init() {
  SAM::init();
  for (int i = n; i; --i) {
    SAM::extend(s[i - 1] - 'a');
  }
  int p = SAM::rt;
  for (int i = n; i; --i) {
    p = SAM::go[p][s[i - 1] - 'a'];
    SegmentTree::rt[p] = SegmentTree::new_node(i);
  }
  SAM::sort(n + 1);
  for (int i = SAM::tot; i > 1; --i) {
    int u = SAM::Q[i], v = SAM::par[u];
    sl[u] = SegmentTree::get_right(SegmentTree::rt[u]) + SAM::len[v];
    sr[u] = sl[u] + SAM::len[u] - SAM::len[v];
    SegmentTree::rt[v] =
        SegmentTree::merge(SegmentTree::rt[u], SegmentTree::rt[v]);
    vec[v].push_back(u);
  }
  for (int i = 1; i <= SAM::tot; ++i) {
    std::sort(vec[i].begin(), vec[i].end(),
              [&](int x, int y) { return s[sl[x] - 1] < s[sl[y] - 1]; });
  }
}
void query(int l, int r) {
  int m = strlen(t);
  int u = SAM::rt, len = 0;
  int ans1 = -1, ans2 = 0;
  for (int i = 0; i <= m; ++i) {
    if (sl[u] + len == sr[u]) {
      len = 0;
      for (const int& v : vec[u]) {
        if (s[sl[v] - 1] < t[i]) {
          continue;
        }
        if (s[sl[v] - 1] == t[i]) {
          u = v;
          len = 1;
        } else {
          if (SegmentTree::query(l, r - i, SegmentTree::rt[v])) {
            if (ans1 == -1 || ans2 < i + 1) {
              ans1 = sl[v] - i;
              ans2 = i + 1;
            }
          }
        }
      }
      if (!len) {
        break;
      }
    } else {
      ++len;
      if (s[sl[u] + len - 2] < t[i]) {
        break;
      }
      if (s[sl[u] + len - 2] > t[i]) {
        if (SegmentTree::query(l, r - i, SegmentTree::rt[u])) {
          if (ans1 == -1 || ans2 < i + 1) {
            ans1 = sl[u] + len - i - 1;
            ans2 = i + 1;
          }
        }
        break;
      }
    }
  }
  if (ans1 == -1) {
    puts("-1");
  } else {
    char tmp = s[ans1 + ans2 - 1];
    s[ans1 + ans2 - 1] = '\0';
    puts(s + ans1 - 1);
    s[ans1 + ans2 - 1] = tmp;
  }
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  init();
  scanf("%d", &q);
  for (int i = 1, l, r; i <= q; ++i) {
    scanf("%d%d%s", &l, &r, t);
    query(l, r);
  }
}