#BS0000012. Giúp Fill Bates (Helping Fill Bates)

Giúp Fill Bates (Helping Fill Bates)

Helping Fill Bates

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a string SS containing only A..Z and a..z. Its characters are indexed from 00.

For each query string T=t0t1…tm−1T=t_0t_1\ldots t_{m-1}, determine whether TT is a subsequence of SS. Equivalently, there must exist indices

0≤p0<p1<⋯<pm−1<∣S∣0\le p_0<p_1<\cdots<p_{m-1}<|S|

such that S[pj]=tjS[p_j]=t_j for every 0≤j<m0\le j<m. If a match exists, print the first and last selected positions for the match with the smallest starting position; break any remaining tie by the smallest ending position.

Input

The first line contains SS.

The second line contains QQ.

The next QQ lines contain query strings.

Output

For each query, print Matched l r if it can be matched; otherwise print Not matched.

Subtasks

  • Subtask 1 — 20%: ∣S∣≤2000|S|\le2000, Q≤100Q\le100.
  • Subtask 2 — 30%: ∣S∣≤100000|S|\le100000, Q≤1000Q\le1000.
  • Subtask 3 — 50%: ∣S∣≤106|S|\le10^6, 1≤Q≤35001\le Q\le3500, ∣T∣≤100|T|\le100.

Examples

Input

aaaaaaaaaaaaaabbbbbbbbbdddddddddddccccccccccccc
3
aaaaaaaaaaaaaaaaaaa
aaaaaaaaaaabbbbbbbbbbbc
abccc

Output

Not matched
Not matched
Matched 0 36

Explanation

For abccc, one valid matching starts at position 00 and ends at position 3636; this pair also satisfies the required tie-breaking rule.