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 JAVA):

Solution:
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;

import static java.lang.Math.min;

public class Test {

  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  int D = 17;
  int n, tn;
  int N = 1 << D;
  char[] s = new char[N], t = new char[N + N];
  int[] sa = new int[N];
  int[] ra = new int[N];
  int[][] sh = new int[D][N];
  int[][] H = new int[D][N];
  int[][] S = new int[D][N];
  int[][] R = new int[D][N];
  int[][][] RS = new int[D][D][N];
  int[][][] RH = new int[D][D][N];
  int[] ans = {-1, -1};
  int glb = -1;

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  void buildSA() {
    int sz = Integer.highestOneBit(n) << 1;
    int[] ord = new int[sz + sz];
    int[] buf = new int[sz + sz];
    Integer[] idx = new Integer[n];
    for (int i = 0; i < n; i++) {
      idx[i] = i;
      ord[i] = s[i];
    }
    for (int i = 1; i < n; i *= 2) {
      final int len = i;
      final int[] od = ord;
      Arrays.sort(
          idx,
          0,
          n,
          (a, b) ->
              od[a] != od[b]
                  ? Integer.compare(od[a], od[b])
                  : od[a + len] != od[b + len]
                      ? Integer.compare(od[a + len], od[b + len])
                      : Integer.compare(a, b));
      buf[idx[0]] = 1;
      for (int j = 1; j < n; j++) {
        int a = idx[j], b = idx[j - 1];
        if (ord[a] == ord[b] && ord[a + len] == ord[b + len]) buf[a] = buf[b];
        else buf[a] = buf[b] + 1;
      }
      int[] tmp = buf;
      buf = ord;
      ord = tmp;
    }
    Arrays.fill(sa, -1);
    Arrays.fill(ra, -1);
    for (int i = 0; i < n; i++) {
      sa[i] = idx[i];
      ra[sa[i]] = i;
    }
  }

  void buildST() {
    int[] c = new int[n];
    for (int d = 0, b = N; b > 1; d++, b >>= 1) {
      for (int i = 0; i < n; i += b) c[i] = 0;
      for (int i = 0; i < n; i++) {
        int j = sa[i] / b * b;
        S[d][j + c[j]++] = sa[i];
      }
      for (int i = 0; i < n; i += b) buildSTN(d, i, min(i + b - 1, n-1));
    }
  }

  void buildH() {
    int l = 0;
    for (int i = 0; i < n; i++) {
      int j = ra[i];
      if (j == 0) {
        sh[0][0] = 0;
        l = 0;
        continue;
      }
      int k = sa[j - 1];
      while (i + l < n && k + l < n && s[i + l] == s[k + l]) l++;
      sh[0][j] = l;
      if (l > 0) l--;
    }
    buildRM(sh, 0, n - 1, n);
  }

  int getRM(int i, int j) {
    if (i == j) return sh[0][i];
    int d = Integer.numberOfTrailingZeros(Integer.highestOneBit(j - i+1));
    return Math.min(sh[d][i], sh[d][j-(1<<d) + 1]);
  }

  void buildRM(int[][] r, int ll, int rr, int max) {
    for (int d = 1, b = 1; b + b <= rr - ll + 1; d++, b <<= 1)
      for (int i = ll; i <= rr; i++)
        r[d][i] = min(r[d - 1][i], i + b <= rr ? r[d - 1][i + b] : max);
  }

  void buildSTN(int d, int ll, int rr) {
    for (int i = ll; i <= rr; i++) R[d][S[d][i]] = i;
    H[d][ll] = 0;
    for (int i = ll + 1; i <= rr; i++) {
      int ri = ra[S[d][i]], rj = ra[S[d][i - 1]];
      H[d][i] = getRM(rj + 1, ri);
    }
    for (int i = ll; i <= rr; i++) {
      RS[d][0][i] = S[d][i];
      RH[d][0][i] = H[d][i];
    }
    buildRM(RS[d], ll, rr, rr);
    buildRM(RH[d], ll, rr, n);
  }

  int getLCP(int i) {
    int j = 0;
    for (; i < n && j < tn; i++, j++) if (s[i] != t[j]) break;
    return j;
  }

  void getMin(int i, int j) {
    if (ans[0] == -1 || ra[i] < ra[ans[0]]) {
      ans[0] = i;
      ans[1] = j;
    }
  }

  int getLeft(int[][] a, int ll, int rr, int min) {
    for (int d = D - 1, b = 1 << d; d >= 0; d--, b >>= 1)
      if (ll + b - 1 <= rr && a[d][ll] > min) ll += b;
    return ll;
  }

  void getGLB(int d, int ll, int rr, int b) {
    int i = ll - 1, j = rr + 1;
    while (j - i > 1) {
      int m = (i + j) / 2;
      if (ra[S[d][m]] > glb) j = m;
      else i = m;
    }
    if (j > rr) return;
    int start = j;
    i = S[d][start];
    int lcp = getLCP(i);
    if (i + lcp <= b) {
      getMin(i, i + lcp);
      return;
    }
    start++;
    while (start <= rr) {
      lcp = min(lcp, H[d][start]);
      ll = getLeft(RH[d], start, rr, lcp - 1);
      j = getLeft(RS[d], start, ll - 1, b - lcp);
      if (j <= ll - 1) {
        int r = S[d][j];
        getMin(r, r + lcp);
        return;
      }
      start = ll;
    }
  }

  void search(int d, int ll, int rr, int i, int j) {
    if (i > rr || j < ll) return;
    if (i <= ll && rr <= j) {
      if (ll == rr) {
        if (ra[ll] <= glb) return;
        int lcp = getLCP(ll);
        if (ll + lcp <= j) getMin(ll, ll + lcp);
        return;
      }
      getGLB(d, ll, rr, j);
      return;
    }
    int mid = (ll + rr) / 2;
    search(d + 1, ll, mid, i, j);
    search(d + 1, mid + 1, rr, i, j);
  }

  int compare(int i) {
    int j;
    for (j = 0; i < n && j < tn; i++, j++)
      if (s[i] < t[j]) return -1;
      else if (s[i] > t[j]) return 1;
    return i < n ? 1 : j < tn ? -1 : 0;
  }

  int getGLB() {
    int ll = -1, rr = n;
    while (rr - ll > 1) {
      int m = (rr + ll) / 2;
      if (compare(sa[m]) <= 0) ll = m;
      else rr = m;
    }
    return ll;
  }

  void start() {
    n = readChars(s);
    buildSA();
    buildH();
    buildST();
    sh = null;
    int q = readInt();
    for (int i = 0; i < q; i++) {
      int ll = readInt(), rr = readInt();
      ll--;
      rr--;
      tn = readChars(t);
      ans[0] = -1;
      ans[1] = -1;
      glb = getGLB();
      if (glb + 1 >= n) {
        writer.println(-1);
        continue;
      }
      search(0, 0, N - 1, ll, rr);
      if (ans[0] == -1) writer.println("-1");
      else writer.println(new String(s, ans[0], ans[1] - ans[0] + 1));
      writer.flush();
    }
  }
}