from collections import deque

# Build query array.
q = deque([(10, 0), (300, 1)])
w = [1e10] * 301
oprs = [1, -1, 10, -10, 100, -100]

while q:
    x, t = q.popleft()
    if t >= w[x]: continue
    w[x] = t
    for opr in oprs:
        nx = x+opr
        if 10 <= nx <= 300:
            q.append((nx, t+1))

# Query input.
T = int(input())
for _ in range(T):
    print(sum(map(lambda x: w[int(x)], input().split())))