import java.io.* ;
import java.util.* ;
public class FastTravelerGame {
try {
while ( ! st.hasMoreTokens ( ) ) {
if ( s == null )
return null ;
}
return st.nextToken ( ) ;
return null ;
}
}
int CASES
= Integer .
parseInt ( next
( ) ) ; while ( CASES-- > 0 ) {
int N
= Integer .
parseInt ( next
( ) ) ; // number of players int M
= Integer .
parseInt ( next
( ) ) ; // number of tiles int D
= Integer .
parseInt ( next
( ) ) ; // number of dices thrown int [ ] move = new int [ M] ;
for ( int k
= 0 ; k
< M
; k
++ ) move
[ k
] = Integer .
parseInt ( next
( ) ) ;
Queue< Integer> queue = new LinkedList< Integer> ( ) ; // player queue
for ( int k = 0 ; k < N; k++ ) queue.add ( k) ;
List< Integer> winners = new LinkedList< Integer> ( ) ;
int [ ] pos = new int [ N] ; // current player position
while ( D-- > 0 ) {
int x
= Integer .
parseInt ( next
( ) ) ; if ( queue.isEmpty ( ) ) {
continue ;
}
int p = queue.poll ( ) ;
pos[ p] += x;
pos[ p] += move[ pos[ p] ] ;
if ( pos[ p] + 1 == M) {
winners.add ( p + 1 ) ;
} else {
queue.add ( p) ;
}
}
if ( winners.isEmpty ( ) ) {
out.println ( - 1 ) ;
} else {
out.print ( winners.remove ( 0 ) ) ;
while ( ! winners.isEmpty ( ) ) {
out.print ( " " + winners.remove ( 0 ) ) ;
}
out.println ( ) ;
}
}
//
out.flush ( ) ;
}
}
CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuKjsKCnB1YmxpYyBjbGFzcyBGYXN0VHJhdmVsZXJHYW1lICB7CgoJc3RhdGljIEJ1ZmZlcmVkUmVhZGVyIGJyID0gbmV3IEJ1ZmZlcmVkUmVhZGVyKG5ldyBJbnB1dFN0cmVhbVJlYWRlcihTeXN0ZW0uaW4pKTsKCXN0YXRpYyBQcmludFdyaXRlciBvdXQgPSBuZXcgUHJpbnRXcml0ZXIobmV3IEJ1ZmZlcmVkT3V0cHV0U3RyZWFtKFN5c3RlbS5vdXQpKTsKCXN0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