(define (get-blue lst)
(define (bd lst mask)
(if (null? lst) 0
(logior (if (= (logand mask (car lst)) mask) mask 0)
(bd (cdr lst) (ash mask 1)))))
(bd lst 1))
(define (get-red lst)
(define (rd lst mask)
(if (null? lst) 0
(logior (if (= (logand mask (car lst)) mask) mask 0)
(rd (cdr lst) (if (< mask 32) (ash mask 1) 1)))))
(let ((p (rd lst 8)))
(logior (ash (logand p 7) 3)
(ash p -3))))
(define (nth str n)
(if (zero? n) (car str)
(nth (cdr str) (- n 1))))
(define (read-strings n)
(if (zero? n) '()
(let ((str (map char->integer
(string->list (let ((cnd (read)))
((if (number? cnd) number->string symbol->string) cnd))))))
(cons (get-blue str) (cons (get-red str) (read-strings (- n 1)))))))
(define (decode data codeline)
(if (null? data) '()
(begin (display (nth codeline (car data)))
(decode (cdr data) codeline))))
(define (read-test)
(let ((data (read-strings (read)))
(codeline (string->list (symbol->string (read)))))
(decode data codeline)))
(define (read-tests n)
(if (zero? n) '() (begin (read-test) (newline) (read-tests (- n 1)))))
((lambda () (read-tests (read))))
(exit)