n = io.read("*n", "*l") for i = 1, n do local s = io.read() local p = 0 for j = 1, 5 do if s:sub(j, j) ~= "0" then p = j break end end if p == 0 then print(0) else print(s:sub(p, 5)) end end