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