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;
using ll = long long;
using ld = long double;
using pr = pair<int, int>;
template <typename T>
inline void _read(T arr, int n) {
  for (int i = 0; i < n; i++) cin >> arr[i];
}
template <typename T>
inline void _write(T arr, int n, bool _space = true, bool _endl = true) {
  if (_space)
    for (int i = 0; i < n; i++) cout << arr[i] << " ";
  else
    for (int i = 0; i < n; i++) cout << arr[i];
  if (_endl) cout << endl;
}
class EdgeSet {
 public:
  class EdgeNode {
   public:
    int nx, to;
    EdgeNode(int n = 0, int t = 0) : nx(n), to(t) {}
  } *E = nullptr;
  int *first = nullptr;
  int ecnt;
  int edgeNum, nodeNum;
  EdgeSet(int NodeNum, int EdgeNum) {
    ecnt = 1;
    edgeNum = EdgeNum;
    nodeNum = NodeNum;
    E = new EdgeNode[EdgeNum + 3];
    first = new int[NodeNum + 3];
    for (int i = 0; i <= NodeNum; i++) {
      first[i] = 0;
    }
  }
  ~EdgeSet() {
    delete[] E;
    delete[] first;
  }
  void Clear() {
    ecnt = 1;
    for (int i = 0; i <= nodeNum; i++) {
      first[i] = 0;
    }
  }
  void AddEdge(int u, int v) {
    E[++ecnt] = EdgeNode(first[u], v);
    first[u] = ecnt;
  }
} *Es = nullptr;
const int MAXN = 200033;
ll cnt[MAXN << 1];
string ans;
class PersistentSegmentTree {
 public:
  struct SegmentTreeNode {
    int lc, rc;
    int sum;
    void New(int sum = 0) {
      lc = rc = 0;
      this->sum = sum;
    }
  } node[MAXN << 6];
  int rt[MAXN << 1];
  int pcnt;
  int New(int sum = 0) {
    node[++pcnt].New(sum);
    return pcnt;
  }
  int Build(int l, int r) {
    int root = New();
    if (l == r) return root;
    int mid = (l + r) / 2;
    node[root].lc = Build(l, mid);
    node[root].rc = Build(mid + 1, r);
    return root;
  }
  int Insert(int k, int l, int r, int root) {
    int now = New(node[root].sum + 1);
    node[now].lc = node[root].lc;
    node[now].rc = node[root].rc;
    if (l == r) return now;
    int mid = (l + r) / 2;
    if (k <= mid)
      node[now].lc = Insert(k, l, mid, node[root].lc);
    else
      node[now].rc = Insert(k, mid + 1, r, node[root].rc);
    return now;
  }
  int Query(int u, int v, int l, int r, int x) {
    if (l == r) {
      return node[v].sum - node[u].sum;
    }
    int mid = (l + r) / 2;
    if (mid >= x)
      return Query(node[u].lc, node[v].lc, l, mid, x);
    else
      return node[node[v].lc].sum - node[node[u].lc].sum +
             Query(node[u].rc, node[v].rc, mid + 1, r, x);
  }
  int MX;
  void Init(int *arr, int n) {
    MX = 0;
    for (int i = 1; i <= n; i++) MX = max(MX, arr[i] + 1);
    rt[0] = Build(1, MX);
    for (int i = 1; i <= n; i++) {
      rt[i] = Insert(arr[i] + 1, 1, MX, rt[i - 1]);
    }
  }
  bool Check(int l, int r, int L, int R) {
    if (L > R) return false;
    int s = Query(rt[l - 1], rt[r], 1, MX, R + 1) -
            Query(rt[l - 1], rt[r], 1, MX, L);
    return s > 0;
  }
} sg;
class SAMautomaton {
 public:
  struct SAMnode {
    int len, link;
    int firstPos;
    bool isClone;
    int L, R;
    vector<int> next;
    void New(int len = 0) {
      this->len = len;
      link = -1;
      isClone = false;
      L = R = firstPos = len;
      next.resize(26);
      for (int i = 0; i < 26; i++) {
        next[i] = 0;
      }
    }
  } node[MAXN << 1];
  int pcnt;
  int last;
  int New(int len = 0) {
    node[++pcnt].New(len);
    return pcnt;
  }
  void Init() {
    pcnt = last = 0;
    node[pcnt].New(0);
  }
  void Extend(int c) {
    int cur = New(node[last].len + 1);
    int p = last;
    while (p != -1 && node[p].next[c] == 0) {
      node[p].next[c] = cur;
      p = node[p].link;
    }
    if (p == -1) {
      node[cur].link = 0;
    } else {
      int q = node[p].next[c];
      if (node[q].len == node[p].len + 1) {
        node[cur].link = q;
      } else {
        int clone = New(node[p].len + 1);
        node[clone].isClone = true;
        node[clone].firstPos = node[q].firstPos;
        node[clone].L = 0x3f3f3f3f;
        node[clone].R = -0x3f3f3f3f;
        node[clone].next = node[q].next;
        node[clone].link = node[q].link;
        while (p != -1 && node[p].next[c] == q) {
          node[p].next[c] = clone;
          p = node[p].link;
        }
        node[q].link = node[cur].link = clone;
      }
    }
    last = cur;
  }
  void dfs(int x) {
    ++tcnt;
    tag[tcnt] = node[x].isClone ? 0 : node[x].len;
    inTag[x] = tcnt;
    for (int _iterator_Variable = Es->first[x], to;
         to = Es->E[_iterator_Variable].to, _iterator_Variable > 0;
         _iterator_Variable = Es->E[_iterator_Variable].nx) {
      dfs(to);
      node[x].L = min(node[x].L, node[to].L);
      node[x].R = max(node[x].R, node[to].R);
    }
    outTag[x] = tcnt;
  }
  int tag[MAXN << 1];
  int inTag[MAXN << 1], outTag[MAXN << 1];
  int tcnt;
  void dfs2(int x) {
    if (cnt[x] > 0) return;
    cnt[x] = 1;
    for (int i = 0; i < 26; i++) {
      if (node[x].next[i] > 0) {
        dfs2(node[x].next[i]);
        cnt[x] += cnt[node[x].next[i]];
      }
    }
  }
  void Build() {
    Es = new EdgeSet(MAXN * 2, MAXN * 4);
    for (int i = 1; i <= pcnt; i++) {
      Es->AddEdge(node[i].link, i);
    }
    tcnt = 0;
    dfs(0);
    dfs2(0);
    cnt[0]--;
    sg.Init(tag, tcnt);
  }
  inline bool Checker(int x, int l, int r) {
    return sg.Check(inTag[x], outTag[x], l, r);
  }
  vector<int> path;
  inline bool Exist(const string &s) {
    path.clear();
    int x = 0;
    path.push_back(x);
    for (int i = 0; i < (int)s.length(); i++) {
      int c = s[i] - 'a';
      if (node[x].next[c] == 0) {
        return false;
      }
      x = node[x].next[c];
      path.push_back(x);
    }
    return true;
  }
  bool Upper_bound(int x, int index, int lastC, const string &s, int l, int r) {
    auto checker = [&](int y) {
      bool ret = Checker(y, l + ans.length(), r);
      return ret;
    };
    if (index >= (int)s.length()) {
      bool hasNext = false;
      for (int i = 0; i < 26; i++) {
        if (node[x].next[i] > 0 && checker(node[x].next[i])) {
          hasNext = true;
          ans.push_back(char('a' + i));
          break;
        }
      }
      if (lastC > s.back() - 'a' || hasNext) {
        return true;
      }
      return false;
    }
    int c = s[index] - 'a';
    if (node[x].next[c] > 0 && checker(node[x].next[c])) {
      ans.push_back(char(c + 'a'));
      if (Upper_bound(node[x].next[c], index + 1, c, s, l, r)) {
        return true;
      } else {
        ans.pop_back();
      }
    }
    for (int i = c + 1; i < 26; i++) {
      if (node[x].next[i] > 0 && checker(node[x].next[i])) {
        ans.push_back(char(i + 'a'));
        return true;
      }
    }
    return false;
  }
  inline void getAns(int l, int r, string &s) {
    ans.clear();
    bool isOK = Upper_bound(0, 0, -1, s, l, r);
    if (!isOK) {
      ans.clear();
    }
  }
} sam;
string s;
void __Main__() {
  sam.Init();
  cin >> s;
  for (int i = 0; i < (int)s.length(); i++) {
    sam.Extend(s[i] - 'a');
  }
  sam.Build();
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r >> s;
    sam.getAns(l, r, s);
    if (ans.length())
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
}
signed main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  __Main__();
  cout << flush;
  return 0;
}