try
while true do
let l1 = read_line () in
let l2 = read_line () in
let p i =
let x s p = String.sub s (4*p) 3 in x l1 i ^ x l2 i in
let r = p 0 in
for i = 1 to 4 do
if p i = r then Printf.printf "%d %s\n" i r
done
done
with End_of_file -> ()
Note that non-ascii characters in the above source code will be escaped (such as \x9f).