import java.util.*;

public class Main {
    private static Queue<Integer> queue = new ArrayDeque<>();
    private static Map<Integer,Integer> map = new HashMap<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        bfs();
        int T = in.nextInt();
        while (T!=0){
            T--;
            int[] arr = new int[4];
            arr[0] = in.nextInt();
            arr[1] = in.nextInt();
            arr[2] = in.nextInt();
            arr[3] = in.nextInt();
            int res = 0;
            for(int t = 0;t<4;t++){
                res += map.get(arr[t]);
            }
            System.out.println(res);
        }
    }
    
    public static void bfs(){
        queue.add(10);
        queue.add(300);
        map.put(10,0);
        map.put(300,1);
        int[] visited = new int[301];
        int[] dir = {-1,1,-10,10,100,-100};
        while(!queue.isEmpty()){
            int len = queue.size();
            for(int i = 0;i<len;i++){
                Integer poll = queue.poll();
                for(int j = 0;j<dir.length;j++){
                    int next = poll + dir[j];
                    if(next<10||next>300){
                        continue;
                    }
                    if(!map.containsKey(next)){
                        map.put(next,map.get(poll)+1);
                        queue.add(next);
                    }
                }
            }
        }
    }
}