Find a Subsequence

All submissions for this problem are available.
Given an array A of N integers A[0], A[1], ..., A[N1] and a string B which is a permutation of "12345".
You have to find a subsequence of 5 elements from A having distinct values such that their relative order is same as B.
Meaning that, if (i_{0}, i_{1}, i_{2}, i_{3}, i_{4}) are the indexes of such a subsequence
(0 <= i_{0} < i_{1} < i_{2} < i_{3} < i_{4} < N) then:
Input
The first line of input contains T(<=60) which is the number of tests cases. The first line of each test case will be an integer N (5<=N<=1000) and a string B containing a permutation of "12345". Next line will contain N integers A[0], A[1], ..., A[N1]. Each of them will be between 10^{9} and +10^{9} (inclusive).
Output
For each test case output five space separated integers in ascending order which are the indexes (i_{0}, i_{1}, i_{2}, i_{3}, i_{4}) of a five length subsequence described before. You may output any solution. If there is no solution just output "1" without quotes.
Example
Input: 2 7 32145 6 17 5 3 13 8 10 7 12345 10 20 30 40 40 20 10 Output: 0 2 3 5 6 1
Explanation of 1st sample: {0, 2, 3, 5, 6} is a valid solution because the values of those indexes {6, 5, 3, 8, 10} will have ranks {3, 2, 1, 4, 5} after sorting. But {0, 2, 3, 4, 5} is not a solution as the values {6, 5, 3, 13, 8} will have ranks {3, 2, 1, 5, 4} after sorting.
Explanation of 2nd sample: There is no five length subsequence in the array that will have ranks {1, 2, 3, 4, 5} after sorting.
Author:  rustinpiece 
Tester:  anton_lunyov 
Editorial  http://discuss.codechef.com/problems/FINDSEQ 
Tags  feb12, hard, rustinpiece 
Date Added:  7122011 
Time Limit:  1.32192  2.05633 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 