n = int(input()) for i in range(n): a, b, c, d, e = map(int, input().split()) print(max(a, b, c, d, e) - min(a, b, c, d, e))