from collections import deque # 预处理:从起点10到所有[10,300]的最少步数 def bfs_1d(): dist = [float('inf')] * 301 dist[10] = 0 q = deque() q.append(10) while q: x = q.popleft() for dx in [1, -1, 10, -10, 100, -100]: nx = x + dx if 10 <= nx <= 300 and dist[nx] > dist[x] + 1: dist[nx] = dist[x] + 1 q.append(nx) for nx in [10, 300]: if dist[nx] > dist[x] + 1: dist[nx] = dist[x] + 1 q.append(nx) return dist dist = bfs_1d() T = int(input()) for _ in range(T): a, b, c, d = map(int, input().split()) ans = dist[a] + dist[b] + dist[c] + dist[d] print(ans)