print((input()[:int(eval(input()))].replace('1','')[:1]or'1'))
print((input()[:int(eval(input()))].replace('1','')[:1]or 1))
print((input()[: int(eval(input()))].replace("1", "")[:1] or "1"))

print((input()[: int(eval(input()))].replace("1", "")[:1] or 1))

-print((input()[: int(eval(input()))].replace("1", "")[:1] or "1")) +print((input()[: int(eval(input()))].replace("1", "")[:1] or 1))