a,b,c,k = list(map(int,input().split()))



out = min(a,k) - max(0,k-a-b)

print(out)

A,B,C,K = list(map(int,input().split()))



out = min(A,K) - max(0,K-A-B)

print(out)

a, b, c, k = list(map(int, input().split()))
out = min(a, k) - max(0, k - a - b)
print(out)

A, B, C, K = list(map(int, input().split()))
out = min(A, K) - max(0, K - A - B)
print(out)

-a, b, c, k = list(map(int, input().split())) -out = min(a, k) - max(0, k - a - b) +A, B, C, K = list(map(int, input().split())) +out = min(A, K) - max(0, K - A - B)