import java.util.*;
public class A{
    public static void main(String arg[]){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        for (int i = 0; i<t; i++){
            System.out.println(esep(scan.nextInt()));
        }
    }
    public static int esep(int a){
        if(a==1){
            return 1;
        }
        int res = 0;
        int i = 1;
        while(i!=a){

            String cur =Integer.toString(i);
            res+=cur.length();

            int c = i%10;

            if(cur.length()==4){

                c++;
                i = c;
                if(i == a){
                    res+=Integer.toString(i).length();

                }

            }else{

                cur+=Integer.toString(c);
                i = Integer.parseInt(cur);
                if(i == a){
                    res+=Integer.toString(i).length();

                }
            }
        }
        return res;

    }
}

import java.io.*;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    static class MyScanner {
        private static BufferedReader bf;
        private static StreamTokenizer tk;
        private static final String ans = "";

        static {
            bf = new BufferedReader(new InputStreamReader(System.in));
            tk = new StreamTokenizer(bf);
        }

        public int nextInt() {
            try {
                tk.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) tk.nval;
        }

        private String nextLine() {
            try {
                tk.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return tk.sval;
        }

    }

    PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    //    Scanner sc = new Scanner(System.in);
    MyScanner sc = new MyScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    private void solve() {
        int t = sc.nextInt();
        while (t-- > 0) {
            int x = sc.nextInt();
            int digit = x % 10, ans = (digit - 1) * 10;
            int v = 0, k = 1;
            while (v != x) {
                v = v * 10 + digit;
                ans += k;
                k++;
            }
            out.println(ans);
        }
        out.flush();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        int t = Integer.parseInt(br.readLine());
        while (t-->0) {
            String s = br.readLine();
            int max = 10,i=Integer.parseInt(s.charAt(0)+"");
            int n = s.length();
            int ans = max*(i-1) + n*(n+1)/2;
            System.out.println(ans);

        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABoringApartments solver = new ABoringApartments();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABoringApartments {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                int n = in.nextInt();
                String s = String.valueOf(n);
                long ans = ((n % 10) - 1) * (10);
                if (s.length() == 1) {
                    out.println(ans + 1);
                } else if (s.length() == 2) {
                    out.println(ans + 3);
                } else if (s.length() == 3) {
                    out.println(ans + 6);
                } else {
                    out.println(ans + 10);
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.util.Scanner;

public class CF_Round_677_Div3_ProblemA_Boring_Apartments {
    public static void main(String[] args) {
        process();
    }

    public static void process() {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for(int i = 0; i < t; ++i) {
            int n = scanner.nextInt();
            int ret = solve(n);
            System.out.println(ret);
        }
    }

    public static int solve(int n) {
        int ret = 0;
        for(int i = 1; i <= 9; ++i) {
            int v = 0;
            for(int j = 1; j <= 4; ++j) {
                v = v * 10 + i;
                ret += j;
                if(v == n) {
                    return ret;
                }
            }
        }

        return ret;
    }

}

import java.util.*;

public class main {
	public static void main(String[] all) {
		Scanner input = new Scanner(System.in);
		int t = input.nextInt();
		while (t-- > 0) {
			int n = input.nextInt();
			String num = ""+n;
			n = n % 10;
			int sum = 0;
			for (int i = 1; i < n; i++) sum += 10;
			for (int i = 1; i < num.length()+1; i++) sum += i;
			System.out.println(sum);
		}
		input.close();
	}
}

import java.util.*;

public class Main {
    public static int calculateSum(int n){
        return (10*n);
    }
    public static void calculate(int n){
      int initSum = calculateSum((n%10)-1);
      String str = Integer.toString(n);
      int len = str.length();
      int secSum = ((len*len + len)/2);
      int sum = initSum+secSum;
      System.out.println(sum);
    }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for(int i=0;i<n;i++){
      int x = sc.nextInt();
      calculate(x);
    }
  }
}

import java.util.Scanner;

public class Main {
     public static void main(String[] args) {
    	Scanner sc=new Scanner(System.in);
    	int t=sc.nextInt();
    	while(t>=1) {
    		int n=sc.nextInt();
    		int cnt=0;
    		int ans=0;
    		int digit=n%10;;
    		while(n!=0) {
    		 cnt+=1;
    		 n/=10;
    		 ans+=cnt;
    		}
    	        ans+=((digit-1)*10);
    			System.out.println(ans);

    		t-=1;
    		System.out.println();
    	}

     }
}

import java.util.Scanner;
public class Boring {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0) {
			int x=sc.nextInt();
			int a=x%10;
			int ans=10*(a-1);
			int e=1;
			while(x>0) {
				x=x/10;
				ans=ans+e;
				e++;
			}
			System.out.println(ans);
		}

	}

}

	    import java.util.*;
	    public class abc{
	        public static void main(String []args){
	            Scanner sc = new Scanner(System.in);
	            int t= sc.nextInt();
	            while(t-- >0) {
	            	 int x = sc.nextInt();
	 	            int rem = x%10;
	 	            int len = Integer.toString(x).length();
	 	            int ans=(rem-1)*10;
	 	            if (len==1){
	 	                ans +=1;
	 	            } else if (len==2){
	 	                ans +=3;
	 	            }else if (len==3){
	 	                ans+=6;
	 	            }else {
	 	                ans+=10;
	 	            }

	 	            System.out.println(ans);
	            }

	        }

	}

import java.util.Scanner;

public class BoringApartments {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int count = kb.nextInt();
		for(int x = 0; x < count; x++) {
			String str = kb.next();
			int num = Integer.parseInt(str.substring(0,1));
			int ans = (num - 1) * 10;
			if(str.length() == 1)
				ans += 1;
			else if (str.length() == 2)
				ans += 3;
			else if (str.length() == 3)
				ans += 6;
			else if (str.length() == 4)
				ans += 10;
			System.out.println(ans);
		}
	}
}

import java.util.Scanner;
import java.util.*;
import java.lang.*;
public class ProblemA
{
	public static void main(String agr[])
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=0; i<t; i++)
		{
		int x=sc.nextInt();
		int count=0;
		int total=0;

		for(int k=1; k<=10000; k++)
		{
			int tr=0;
			String sum="";
			for(int j=0; j<4; j++)
			{
			String s=Integer.toString(k);
			sum= sum+s;
			count++;
			if(Integer.parseInt(sum)==x)
			{
				tr=1;
				break;
			}
			}
			if(tr==1)
				break;
		}
		if(count%4==0)
		total=(count/4)*10;
		else if(count%4==1)
			total=(count/4)*10+1;
		else if(count%4==2)
			total=(count/4)*10+3;
		else if(count%4==3)
			total=(count/4)*10+6;
		System.out.println(total);
		}
	}
}

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int t = input.nextInt();

        while(t-- > 0) {
            int n = input.nextInt();
            int ans = 0;
            for(int i = 1; i <= 9; i++) {
                int x = 0;
                int cnt = 0;
                boolean found = false;
                while(true) {
                    x *= 10; x += i;
                    cnt++;
                    if(x > 10000) break;
                    ans += cnt;
                    if(x == n) {
                        found = true;
                        break;
                    }
                }
                if(found) break;
            }
            System.out.println(ans);
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;

import javax.naming.InitialContext;
import javax.naming.directory.SearchControls;

public class Main {

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		Thread.sleep(3000);
		// int t = sc.nextInt();
		int t = sc.nextInt();
		for(int i =0;i<t;i++) {
			String s = sc.nextLine();
			if(s.charAt(0)=='1') {
				System.out.println((s.length()*(s.length()+1))/2);
			}
			else {
				int res =10;
				res*=(Integer.parseInt(s.charAt(0)+"")-1);
				res+=(s.length()*(s.length()+1))/2;
				System.out.println(res);
			}
		}

	}
}

class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++)
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader reader = new FastReader();
		int t = reader.nextInt();
		while (t-- > 0) {
			String s = reader.nextLine();
			int cnt = 0;
			for (int i = 0; i < s.charAt(0) - '1'; ++i)
				cnt += 10;
			cnt += s.length() * (s.length() + 1) / 2;
			System.out.println(cnt);
		}
		reader.close();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine().trim());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine().trim();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readArray(int size) {
			int[] ar = new int[size];
			int i = 0;
			try {
				for (String s : br.readLine().trim().split("\\s+"))
					ar[i++] = Integer.parseInt(s);
			} catch (IOException e) {
				e.printStackTrace();
			}
			return ar;
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader reader = new FastReader();
		int t = reader.nextInt();
		while (t-- > 0) {
			String s = reader.nextLine();
			int cnt = 10 * (s.charAt(0) - '1');
			cnt += s.length() * (s.length() + 1) / 2;
			System.out.println(cnt);
		}
		reader.close();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine().trim());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine().trim();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readArray(int size) {
			int[] ar = new int[size];
			int i = 0;
			try {
				for (String s : br.readLine().trim().split("\\s+"))
					ar[i++] = Integer.parseInt(s);
			} catch (IOException e) {
				e.printStackTrace();
			}
			return ar;
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

import java.util.*;
public class A1433 {
    static int[] sums= { 1, 3, 6, 10};
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int times = input.nextInt();
        for(int i=0;i<times;i++){
            int number = input.nextInt();
            int len = (int)Math.log10(number);
            int f = number / (int)Math.pow(10,len)-1;
            System.out.println(10*f+sums[len]);
        }
    }
}

import java.awt.desktop.SystemEventListener;
import java.awt.image.BandedSampleModel;
import java.util.Scanner;

public class CF_1433A {
    private static int countDigits(int n) {
        int count = 0;
        while (n > 0) {
            n /= 10;
            count++;
        }
        return count;
    }

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int testCases = in.nextInt();
        while (testCases > 0) {
            int answeringNumber = in.nextInt();
            if (answeringNumber == 1) {
                System.out.println(1);
                testCases--;
                continue;
            }
            int pressingCount = (answeringNumber % 10 - 1) * 10;
            int countForCurrentChar = countDigits(answeringNumber) * (countDigits(answeringNumber) + 1) / 2;
            pressingCount += countForCurrentChar;
            System.out.println(pressingCount);
            testCases--;
        }
    }
}

import java.util.Scanner;

public class _90BoringApartments {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int cases =sc.nextInt();

		while(cases>0) {
		int n=sc.nextInt();
		int sum=0;

		for(int i=1;i<=9;i++) {
			String temp=i+"";
			for(int j=0;j<4;j++) {
				sum+=temp.length();
				if(n==Integer.parseInt(temp)) {
					System.out.println(sum);
					break;
				}
				temp=temp+i;
			}
		}
			cases--;
		}
	}

}

import java.io.*;
import java.util.*;
public class Codeforce{
    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(read.readLine());
        int[] outputs = new int[t];
        for(int i=0; i<t; i++){
            String N = read.readLine();
            int n = Integer.parseInt(N.substring(0,1));
            outputs[i] = 10*(n-1) + (N.length()*(N.length()+1)/2);
        }
        for(int output:outputs)System.out.println(output);

    }
}

import java.util.*;

public class boring{
    public static void main(String[] args){
     Scanner sc = new Scanner(System.in);
     int cases = sc.nextInt();
     for(int i = 0; i < cases; i++){
         int value = sc.nextInt();
         int part = value % 10;
         int le = String.valueOf(value).length();
         double current = le / 2.0 * (2.0 + (le - 1));
         int total = ((part - 1) * 10) + (int)current;
         System.out.println(total);
     }
    }
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int limit = scan.nextInt();
        for (int test = 0; test < limit; test++) {
            int x = scan.nextInt();
            System.out.println((int)((x % 10 - 1) * 10 + (1 + (x + "").length()) / 2.0 * (x + "").length()));
        }
    }
}

//package ex1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) {
        int nb = FastScanner.nextInt();
        for(int i = 0; i < nb; i++){
            String val = FastScanner.next();
            int digit = Integer.parseInt(val.charAt(0)+"");
            int length = val.length();

            int res = 10 * (digit - 1);
            if(length == 1){
                res += 1;
            }
            else if(length == 2){
                res += 3;
            }
            else if(length == 3){
                res += 6;
            }
            else if(length == 4){
                res += 10;
            }
            System.out.println(res);
        }
    }
}

class FastScanner {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer st = new StringTokenizer("");

    public static String next(){
        while (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {}
        }
        return st.nextToken();
    }

    public static String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {}
        return "";
    }

    public static char nextChar(){
        return next().charAt(0);
    }

    public static int nextInt(){
        return Integer.parseInt(next());
    }

    public static long nextLong(){
        return Long.parseLong(next());
    }

    public static double nextDouble(){
        return Double.parseDouble(next());
    }
}

import java.util.*;
import java.math.*;
public class Main{
    public static void main(String[] args) throws java.lang.Exception {

        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            int n = sc.nextInt();

            int total = 0;
            for (int i = 1; i <= 9; i++)
            {
                int sum = 0;
                for (int j = 1; j <= 4; j++)
                {
                    sum = sum * 10 + i;
                    total += j;
                    if (sum==n) {

                        break;
                    }

                }
                if (sum==n) {
                    System.out.println(total);
                    break;
                }

            }
        }
    }

}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        TaskA taskA = new TaskA();
        taskA.solve(in);

        in.close();
    }

    static class TaskA {
        public void solve(Scanner in) {
            int tt = in.nextInt();
            while (tt-- > 0) {
                int res = 0;
                String s = in.next();
                int len = s.length();
                for (char ch = '1'; ch < s.charAt(0); ++ch) {
                    res += 10;
                }
                res += len * (len + 1) / 2;
                System.out.println(res);
            }
        }
    }
}

// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class FS1 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
        t=scan.nextInt();
        while(t-->0){
            String x=scan.next();
            int ans=0;
            for(int i=1;i<=9;i++){
                int v=0;
                String temp="";
                for(int j=1;j<=4;j++){
                    temp+=i;
                    if(temp.compareTo(x)<=0){
                        ans+=j;
                    }
                }
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AyushKM
 */
public class Main {
   public static void main(String[] args) {
      InputStream inputStream = System.in;
      OutputStream outputStream = System.out;
      InputReader in = new InputReader(inputStream);
      OutputWriter out = new OutputWriter(outputStream);
      ABoringApartments solver = new ABoringApartments();
      int testCount = Integer.parseInt(in.next());
      for (int i = 1; i <= testCount; i++)
         solver.solve(i, in, out);
      out.close();
   }

   static class ABoringApartments {
      public void solve(int testNumber, InputReader in, OutputWriter out) {
         char ch[] = in.next().toCharArray();
         int l = ch.length;
         int n = ch[0] - 48;
         int sum = (n - 1) * 4 + l, sumL = 0;
         for (int x = 1; x <= sum; x++) {
            int i = x;
            if (x > 4) {
               i = x % 4;
            }
            if (x % 4 == 0)
               i = 4;
            sumL += i;
//            out.println(i);
         }
         out.println(sumL);
      }

   }

   static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private InputReader.SpaceCharFilter filter;

      public InputReader(InputStream stream) {
         this.stream = stream;
      }

      public int read() {
         if (numChars == -1) {
            throw new InputMismatchException();
         }
         if (curChar >= numChars) {
            curChar = 0;
            try {
               numChars = stream.read(buf);
            } catch (IOException e) {
               throw new InputMismatchException();
            }
            if (numChars <= 0) {
               return -1;
            }
         }
         return buf[curChar++];
      }

      public String nextString() {
         int c = read();
         while (isSpaceChar(c)) {
            c = read();
         }
         StringBuilder res = new StringBuilder();
         do {
            if (Character.isValidCodePoint(c)) {
               res.appendCodePoint(c);
            }
            c = read();
         } while (!isSpaceChar(c));
         return res.toString();
      }

      public boolean isSpaceChar(int c) {
         if (filter != null) {
            return filter.isSpaceChar(c);
         }
         return isWhitespace(c);
      }

      public static boolean isWhitespace(int c) {
         return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }

      public String next() {
         return nextString();
      }

      public interface SpaceCharFilter {
         public boolean isSpaceChar(int ch);

      }

   }

   static class OutputWriter {
      private final PrintWriter writer;

      public OutputWriter(OutputStream outputStream) {
         writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
      }

      public OutputWriter(Writer writer) {
         this.writer = new PrintWriter(writer);
      }

      public void close() {
         writer.close();
      }

      public void println(int i) {
         writer.println(i);
      }

   }
}

import java.util.*;
import java.io.*;
public class CodeforceSolution
{
	public static void main(String args[])
	{
			Scanner sc=new Scanner(System.in);
			int t=sc.nextInt();
			while(t!=0)
			{
				int x=sc.nextInt();
				int sum=1,c=0,res=1;
				while(res!=x)
				{
					res=res*10+res%10;
					if(res>10000)
					{
						res=res%10+1;
					}
					c=noOfdig(res);
					sum=sum+c;
				}
				System.out.println(sum);
				t--;
			}
	}
	public static int noOfdig(int n)
	{
			int s=0;
			for(;n>0;n/=10)
			{
				s++;
			}
			return s;
	}
}

import java.util.Scanner;
public class BoringApartments
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0)
        {
            int x = sc.nextInt();
            int target = x%10;
            long total = 0;
            for (int d = 1; d <= target; d++)
            {
                int c = 0;
                int num = d;
                while ((num <= 10000) && (d != target || num <= x))
                {
                    c += 1;
                    num = num*10 + d;
                }
                total += c*(c+1)/2;
            }
            System.out.println(total);
        }
    }
}

//package CodeForces.Round677Div3;

import java.io.*;import java.util.*;import java.math.*;
public class A
{
    static long mod=1000000007l;
    static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
    static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb;

    static public void main(String[] args)throws Exception
    {
        st=new StringTokenizer(br.readLine());
        int t=i();
        sb=new StringBuilder(1000000);

        while(t-->0) {
            String s = s() ;
            int len = s.length() ;
            int n = Integer.parseInt(String.valueOf(s.charAt(0))) ;
            int ans = (10 * (n-1)) +  ((len * (len+1)) /2) ;
            sl(ans);
        }
        p(sb) ;
    }

    static void s(String s){sb.append(s);}
    static void s(int s){sb.append(s);}
    static void s(long s){sb.append(s);}
    static void s(char s){sb.append(s);}
    static void s(double s){sb.append(s);}
    static void ss(){sb.append(' ');}
    static void sl(String s){sb.append(s);sb.append("\n");}
    static void sl(int s){sb.append(s);sb.append("\n");}
    static void sl(long s){sb.append(s);sb.append("\n");}
    static void sl(char s){sb.append(s);sb.append("\n");}
    static void sl(double s){sb.append(s);sb.append("\n");}
    static void sl(){sb.append("\n");}
    static int max(int a,int b){return a>b?a:b;}
    static int min(int a,int b){return a<b?a:b;}
    static int abs(int a){return Math.abs(a);}
    static long max(long a,long b){return a>b?a:b;}
    static long min(long a,long b){return a<b?a:b;}
    static long abs(long a){return Math.abs(a);}
    static int sq(int a){return (int)Math.sqrt(a);}
    static long sq(long a){return (long)Math.sqrt(a);}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
    static boolean pa(String s,int i,int j)
    {
        while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;
        return true;
    }
    static int ncr(int n,int c,long m)
    {
        long a=1l;
        for(int x=n-c+1;x<=n;x++)a=((a*x)%m);
        long b=1l;
        for(int x=2;x<=c;x++)b=((b*x)%m);
        return (int)((a*(mul((int)b,m-2,m)%m))%m);
    }
    static boolean[] sieve(int n)
    {
        boolean bo[]=new boolean[n+1];
        bo[0]=true;bo[1]=true;
        for(int x=4;x<=n;x+=2)bo[x]=true;
        for(int x=3;x*x<=n;x+=2)if(!bo[x])for(int y=x*x;y<=n;y+=x)bo[y]=true;
        return bo;
    }
    static int[] fac(int n)
    {
        int bo[]=new int[n+1];
        for(int x=1;x<=n;x++)for(int y=x;y<=n;y+=x)bo[y]++;
        return bo;
    }
    static long mul(long a,long b,long m)
    {
        long r=1l;
        a%=m;
        while(b>0)
        {
            if((b&1)==1)r=(r*a)%m;
            b>>=1;
            a=(a*a)%m;
        }
        return r;
    }
    static int i()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    static double d()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Double.parseDouble(st.nextToken());
    }
    static void p(Object p){System.out.print(p);}
    static void p(String p){System.out.print(p);}
    static void p(int p){System.out.print(p);}
    static void p(double p){System.out.print(p);}
    static void p(long p){System.out.print(p);}
    static void p(char p){System.out.print(p);}
    static void p(boolean p){System.out.print(p);}
    static void pl(Object p){System.out.println(p);}
    static void pl(String p){System.out.println(p);}
    static void pl(int p){System.out.println(p);}
    static void pl(char p){System.out.println(p);}
    static void pl(double p){System.out.println(p);}
    static void pl(long p){System.out.println(p);}
    static void pl(boolean p){System.out.println(p);}
    static void pl(){System.out.println();}
    static int[] ari(int n)throws IOException
    {
        int ar[]=new int[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());
        return ar;
    }
    static int[][] ari(int n,int m)throws IOException
    {
        int ar[][]=new int[n][m];
        for(int x=0;x<n;x++)
        {
            if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());
        }
        return ar;
    }
    static long[] arl(int n)throws IOException
    {
        long ar[]=new long[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());
        return ar;
    }
    static long[][] arl(int n,int m)throws IOException
    {
        long ar[][]=new long[n][m];
        for(int x=0;x<n;x++)
        {
            if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());
        }
        return ar;
    }
    static String[] ars(int n)throws IOException
    {
        String ar[]=new String[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=st.nextToken();
        return ar;
    }
    static double[] ard(int n)throws IOException
    {
        double ar[]=new double[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());
        return ar;
    }
    static double[][] ard(int n,int m)throws IOException
    {
        double ar[][]=new double[n][m];
        for(int x=0;x<n;x++)
        {
            if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());
        }
        return ar;
    }
    static char[] arc(int n)throws IOException
    {
        char ar[]=new char[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);
        return ar;
    }
    static char[][] arc(int n,int m)throws IOException
    {
        char ar[][]=new char[n][m];
        for(int x=0;x<n;x++)
        {
            String s=br.readLine();
            for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);
        }
        return ar;
    }
    static void p(int ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(int a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(int ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(int a[]:ar)
        {
            for(int aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(long ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(long a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(long ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(long a[]:ar)
        {
            for(long aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(String ar[])
    {
        int c=0;
        for(String s:ar)c+=s.length()+1;
        StringBuilder sb=new StringBuilder(c);
        for(String a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(double a:ar)
        {
            sb.append(a);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(double a[]:ar)
        {
            for(double aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(char ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(char aa:ar)
        {
            sb.append(aa);
            sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(char ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(char a[]:ar)
        {
            for(char aa:a)
            {
                sb.append(aa);
                sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
}

import java.util.Scanner;

public class NewClass10 {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int q = scan.nextInt();
        while (q-- > 0) {
            String s = scan.next();
            int ch = s.charAt(0) - '0';
            long res = (ch - 1) * 10;
            res += (s.length() * (s.length() + 1)) / 2;

            System.out.println(res);
        }

    }
}

import java.util.*;

public class Task {
	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		int t = input.nextInt();

		for (int a = 0; a < t; a++) {

			int x = input.nextInt();
			int i = 0;
			int counter = 0;
			int increase = 1;

			while (i != x) {

				i += increase;
				increase = increase * 10;
				counter += Integer.toString(i).length();

				if (increase % 10000 == 0) {

					increase = increase / 10000 + 1;
					if (i == x) {
						break;
					} else {
						i = 0;
					}
				}
			}
			System.out.println(counter);
		}
	}
}

import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while (t-- > 0) {
			int n = s.nextInt();
			int ans = 0;
			outer:
			for (int i = 1; i <= 9; i++) {
				String str = "";
				for (int j = 1; j < 5; j++) {
					str += i;
					if (str.equals(n + "")) {
						ans += j;
						break outer;
					} else {
						ans += j;
					}
				}
			}
			System.out.println(ans);

		}
	}

}

import java.util.*;

import java.io.*;

public class CCTrial {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {
			String s=br.readLine();
			int n=Integer.parseInt(s);
			int x=n%10;
			if(n<10) x=n;
			int a[]=new int[] {0,1,3,6,10};
			int ans=((x-1)*10)+a[s.length()];
			System.out.println(ans);
		}

	}
	public static  String sub(String s,int i) {
		return s.substring(0,i);
	}
}

//package Codeforces;
import java.util.Scanner;

public class Boring
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0)
        {
            int n = sc.nextInt();
            int res = 0;
            res = ((n % 10)-1) * 10;
            int len = Integer.toString(n).length();
            len = len*(len+1)/2;
            res = res + len;
            System.out.println(res);
        }
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        int x = s.nextInt();

        while(x-- > 0) {
            String v = s.next();
            int n = v.length();
            int k = Integer.parseInt(""+v.charAt(0));
            int res = (int) (Math.pow(n, 2)+n)/2+(k-1)*10;
            System.out.println(res);
        }
    }
}

import java.util.*;

public class NumpressCF {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while (t-->0) {
			String x=scan.next();
			int ok=10;
			int first=x.charAt(0)-'0';
			int l=x.length();
			int ans=((first-1)*ok) + ((l*(l+1))/2);
			System.out.println(ans);

		}

	}

}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n!=0) {
			int i = sc.nextInt();
			int sum = 0;
			sum = (i%10-1)*10;
			int j=1;
			String s = i+"";
			int k = s.length();
			while(k!=0) {
				sum+= j;
				j++;
				k--;
			}
			System.out.println(sum);
			n--;
		}
	sc.close();
}

}

import java.io.*;
import java.lang.*;
import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while(t-->0){
           int n  = scan.nextInt();
           int ans = 0;
           int number = n%10;
           ans = ans+(number-1)*10;
           int i=1;
           while(n!=0){
                       n/=10;
                       ans+=i;
                       i++;
           }
        System.out.println(ans);
        }
    }
}

import java.util.*; public class abcd{ public static void main(String args[]) {  Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0;i<t;i++) { int x=in.nextInt(); int n=0; int a=x; while(a!=0) { a=a/10; n++; } int d=x%10; int s=0; if(n==1) s=1; if(n==2) s=3; if(n==3) s=6; if(n==4) s=10; s=s+10*(d-1); System.out.println(s); } } }

import java.util.*;
public class er{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		int n=sc.nextInt();
		int lastDigit=n%10;
		int totalNumber=0;
		while(n>0){
			totalNumber++;
			n/=10;
		}
        int to=0;
		if(lastDigit>1){
           to=(lastDigit-1)*10;
		}
		int toAdd=0;
		switch(totalNumber){
			case 1:
               toAdd=1;
               break;
			case 2:
               toAdd=3;
               break;
			case 3:
               toAdd=6;
               break;
			case 4:
               toAdd=10;
               break;
		}
		int total=toAdd+to;
		System.out.println(total);
	}
   }
}

import java.util.*;
import java.io.*;
public class Solution{
public static void func(int N){

    if(N==1){
        System.out.println(1);
        return;
    }
    if(N==11){
        System.out.println(3);
        return;
    }
    if(N==111){
         System.out.println(6);
        return;
    }
    if(N==1111){
         System.out.println(10);
        return;
    }

        if(N==2){
            System.out.println(11);
            return;
        }
        if(N==22){
             System.out.println(13);
            return;
        }
        if(N==222){
             System.out.println(16);
            return;
        }
        if(N==2222){
             System.out.println(20);
            return;
        }

        if(N==3){
             System.out.println(21);
            return;
        }
        if(N==33){
             System.out.println(23);
            return;
        }
        if(N==333){
             System.out.println(26);
            return;
        }
        if(N==3333){
             System.out.println(30);
            return;
        }

        if(N==4){
             System.out.println(31);
            return;
        }
        if(N==44){
             System.out.println(33);
            return;
        }
        if(N==444){
             System.out.println(36);
            return;
        }
        if(N==4444){
             System.out.println(40);
            return;
        }

        if(N==5){
             System.out.println(41);
            return;
        }
        if(N==55){
             System.out.println(43);
            return;
        }
        if(N==555){
             System.out.println(46);
            return;
        }
        if(N==5555){
             System.out.println(50);
            return;
        }

        if(N==6){
             System.out.println(51);
            return;
        }
        if(N==66){
             System.out.println(53);
            return;
        }
        if(N==666){
             System.out.println(56);
            return;
        }
        if(N==6666){
             System.out.println(60);
            return;
        }

        if(N==7){
             System.out.println(61);
            return;
        }
        if(N==77){
             System.out.println(63);
            return;
        }
        if(N==777){
             System.out.println(66);
            return;
        }
        if(N==7777){
             System.out.println(70);
            return;
        }

        if(N==8){
             System.out.println(71);
            return;
        }
        if(N==88){
             System.out.println(73);
            return;
        }
        if(N==888){
             System.out.println(76);
            return;
        }
        if(N==8888){
             System.out.println(80);
            return;
        }

        if(N==9){
             System.out.println(81);
            return;
        }
        if(N==99){
             System.out.println(83);
            return;
        }
        if(N==999){
             System.out.println(86);
            return;
        }
        if(N==9999){
             System.out.println(90);
            return;
        }

    }

public static void main(String[]args){

try{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(bf.readLine());
while(t--!=0){

int N=Integer.parseInt(bf.readLine());

func(N);
}

}

catch(Exception e){

}}}

import java.util.*;
import java.io.*;

public class sol {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        public FastReader(String giveMeFile) throws IOException
        {
            File file = new File("input.txt");
            br = new BufferedReader(new FileReader(file));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static boolean[] SES(int n) {
        // SES Stands for SieveOfEratoSthenes
        boolean isPrime[] = new boolean[n+1];
        Arrays.fill(isPrime, true);

        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2;i*i<=n;i++) {
            for(int j = 2*i;j<=n;j+=i) {
                isPrime[j] = false;
            }

        }
        return isPrime;
    }

    public static int gcd(int a, int b) {
        return a % b == 0 ? b : gcd(b, a%b);
    }

    public static long fastPower(long a, long b, long n) {
        long res = 1;
        while(b > 0) {
            if( (b&1) != 0) {
                res = (res % n * a % n) % n;
            }

            a = (a % n * a % n) % n;
            b = b >> 1; // dividing by 2
        }
        return res;
    }

    public static int binarySearch(long arr[], int low, int high, long x)
    {
        if (high >= low) {
            int mid = low + (high - low) / 2;
            if ((mid == 0 || x < arr[mid - 1]) && arr[mid] == x)
                return mid;
            else if (x < arr[mid])
                return binarySearch(arr, (mid + 1), high, x);
            else
                return binarySearch(arr, low, (mid - 1), x);
        }
        return -1;
    }

    public static void main(String[] args) throws IOException {

        // ************** Providing input File
        // File file = new File("input.txt");
        // BufferedReader br = new BufferedReader(new FileReader(file));

        // *************** Input for Online Judges with Buffered Reader
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // ************* Input for Online Judges with Scanner class
        // Reading with Scanner class
        // Scanner sc = new Scanner(file);
        // sc.useDelimiter("\\Z");

        // ***************** Printing Outout to output file.
        // PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        // printWriter.println("something here");
        // printWriter.close();    --->>  // only this close method will flush the output from the buffer to the output file.

        FastReader read = new FastReader();

        int t = read.nextInt();

        while(t-- != 0) {

            // String temp = read.next();

           int n = read.nextInt();

           int sum = 0;
            int num =0;
            if(n == 1) {
                sum += 1;
            }
            else if(n == 11) {
                sum += 3;
            }
            else if(n == 111) {
                sum += 6;
            }
            else if(n == 1111) {
                sum += 10;
            }
            else if(n == 2) {
                sum += 11;
            }
            else if(n == 3) {
                sum += 21;
            }
            else if(n == 4) {
                sum += 31;
            }
            else if(n == 5) {
                sum += 41;
            }
            else if(n == 6) {
                sum += 51;
            }
            else if(n == 7) {
                sum += 61;
            }
            else if(n == 8) {
                sum += 71;
            }
            else if(n == 9) {
                sum += 81;
            }
            else if(n / 2 == 1 || n / 2 == 11 || n / 2 == 111 || n / 2 == 1111) {
                num = 2-1;
                sum += 10*num;

                if(n == 2) sum += 1;
                if(n == 22) sum += 3;
                if(n == 222) sum += 6;
                if(n == 2222) sum += 10;

               }
              else if(n / 3 == 1 || n / 3 == 11 || n / 3 == 111 || n / 3 == 1111) {
                num = 3-1;
                sum += 10*num;

                if(n == 3) sum += 1;
                if(n == 33) sum += 3;
                if(n == 333) sum += 6;
                if(n == 3333) sum += 10;

               }
              else if(n / 4 == 1 || n / 4 == 11 || n / 4 == 111 || n / 4 == 1111) {
                num = 4-1;
                sum += 10*num;

                if(n == 4) sum += 1;
                if(n == 44) sum += 3;
                if(n == 444) sum += 6;
                if(n == 4444) sum += 10;

               }
               else if(n / 5 == 1 || n / 5 == 11 || n / 5 == 111 || n / 5 == 1111) {
                num = 5-1;
                sum += 10*num;

                if(n == 5) sum += 1;
                if(n == 55) sum += 3;
                if(n == 555) sum += 6;
                if(n == 5555) sum += 10;

               }
               else if(n / 6 == 1 || n / 6 == 11 || n / 6 == 111 || n / 6 == 1111) {
                num = 6-1;
                sum += 10*num;

                if(n == 6) sum += 1;
                if(n == 66) sum += 3;
                if(n == 666) sum += 6;
                if(n == 6666) sum += 10;

               }

               else if(n / 7 == 1 || n / 7 == 11 || n / 7 == 111 || n / 7 == 1111) {
                num = 7-1;
                sum += 10*num;

                if(n == 7) sum += 1;
                if(n == 77) sum += 3;
                if(n == 777) sum += 6;
                if(n == 7777) sum += 10;

               }

               else if(n / 8 == 1 || n / 8 == 11 || n / 8 == 111 || n / 8 == 1111) {
                num = 8-1;
                sum += 10*num;

                if(n == 8) sum += 1;
                if(n == 88) sum += 3;
                if(n == 888) sum += 6;
                if(n == 8888) sum += 10;

               }

               else if(n / 9 == 1 || n / 9 == 11 || n / 9 == 111 || n / 9 == 1111) {
                num = 9-1;
                sum += 10*num;

                if(n == 9) sum += 1;
                if(n == 99) sum += 3;
                if(n == 999) sum += 6;
                if(n == 9999) sum += 10;

               }

               System.out.println(sum);
        }

    }

    }

import static java.lang.Math.*;

import java.io.*;
import java.util.*;

public class A {

    final static PrintWriter out = new PrintWriter(System.out);
    final static FastScanner sc = new FastScanner(System.in);

    public static void main(String[] args) throws IOException {
        A ob = new A();
        int t = sc.readInt();
        ob.precalculate();
        while (t-- > 0) {
            ob.solve();
        }
        out.close();
    }

    int v[] = new int [36];
    void precalculate(){
        int k = 0;
        for(int i = 1; i <= 9; ++i){
            v[k++] = i;
            v[k++] = i * 10 + i;
            v[k++] = i * 100 + i * 10 + i;
            v[k++] = i * 1000 + i * 100 + i * 10 + i;
        }
//        Debug.dbg(v);
    }
    void solve() throws IOException {
        int n = sc.readInt();
        int ans = 0;
        for(int i = 0; i < 36; ++i){
            ans += (floor(log10(v[i])) + 1);
            if(v[i] == n){
                break;
            }
        }
        out.println(ans);
    }

    public static class Utility {
        static final double EPS = 10e-6;

        public static int lower_bound(int[] a, int x) {
            int left = 0, right = a.length, mid = -1;

            while (left < right) {
                mid = (left + right) / 2;
                if (a[mid] >= x) {
                    right = mid;
                } else {
                    left = mid + 1;
                }

            }
            return left;
        }

        public static int upper_bound(int[] arr, int x) {
            int left = 0, right = arr.length, mid = -1;
            while (left < right) {
                mid = (left + right) / 2;
                if (arr[mid] > x) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            return left;
        }

        public static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        public static int lcm(int a, int b) {
            return a * b / gcd(a, b);
        }

        public static long fast_pow_mod(long b, long x, int mod) {
            if (x == 0)
                return 1;
            if (x == 1)
                return b;
            if (x % 2 == 0)
                return fast_pow_mod(b * b % mod, x / 2, mod) % mod;

            return b * fast_pow_mod(b * b % mod, x / 2, mod) % mod;
        }

        public static int fast_pow(int b, int x) {
            if (x == 0)
                return 1;
            if (x == 1)
                return b;
            if (x % 2 == 0)
                return fast_pow(b * b, x / 2);

            return b * fast_pow(b * b, x / 2);
        }

        public static long choose(long n, long k) {
            k = Math.min(k, n - k);
            long val = 1;
            for (int i = 0; i < k; ++i)
                val = val * (n - i) / (i + 1);
            return val;
        }

        public static long permute(int n, int k) {
            if (n < k)
                return 0;
            long val = 1;

            for (int i = 0; i < k; ++i)
                val = (val * (n - i));

            return val;
        }
    }

    public static class FastScanner {
        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar, numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        public FastScanner(String file) throws IOException {
            this.stream = new FileInputStream(file);
        }

        public int readChar() throws IOException {
            if (curChar >= numChars) {
                curChar = 0;
                numChars = stream.read(buf);
            }

            if (numChars == -1)
                return numChars;

            return buf[curChar++];
        }

        public int readInt() throws IOException {
            int c = readChar(), sgn = 1;

            while (isSpace(c))
                c = readChar();

            if (c == '-') {
                sgn = -1;
                c = readChar();
            }

            int res = 0;

            do {
                res = (res << 1) + (res << 3);
                res += c - '0';
                c = readChar();
            } while (!isSpace(c));

            return res * sgn;
        }

        public String readString() throws IOException {
            int c = readChar();

            while (isSpace(c))
                c = readChar();

            StringBuilder res = new StringBuilder();

            do {
                res.appendCodePoint(c);
                c = readChar();
            } while (!isSpace(c));

            return res.toString();
        }

        public double readDouble() throws IOException {
            int c = readChar(), sgn = 1;

            while (isSpace(c))
                c = readChar();

            if (c == '-') {
                sgn = -1;
                c = readChar();
            }

            double res = 0;

            while (!isSpace(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Utility.fast_pow(10, readInt());

                res *= 10;
                res += c - '0';
                c = readChar();
            }

            if (c == '.') {
                c = readChar();
                double m = 1;

                while (!isSpace(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Utility.fast_pow(10, readInt());

                    m /= 10;
                    res += (c - '0') * m;
                    c = readChar();
                }
            }

            return res * sgn;
        }

        public long readLong() throws IOException {
            int c = readChar(), sgn = 1;

            while (isSpace(c))
                c = readChar();

            if (c == '-') {
                sgn = -1;
                c = readChar();
            }

            long res = 0;

            do {
                res = (res << 1) + (res << 3);
                res += c - '0';
                c = readChar();
            } while (!isSpace(c));

            return res * sgn;
        }
    public int[] readIntArray(int n) throws IOException {
        int a[] = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = readInt();
        }
        return a;
    }

    public long[] readLongArray(int n) throws IOException {
        long a[] = new long[n];
        for (int i = 0; i < n; ++i) {
            a[i] = readLong();
        }
        return a;
    }

    public String[] readStringArray(int n) throws IOException {
        String a[] = new String[n];
        for (int i = 0; i < n; ++i) {
            a[i] = readString();
        }
        return a;
    }
    public boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
}

    public static class Debug {
        public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

        private static <T> String ts(T t) {
            if (t == null) {
                return "null";
            }
            try {
                return ts((Iterable) t);
            } catch (ClassCastException e) {
                if (t instanceof int[]) {
                    String s = Arrays.toString((int[]) t);
                    return "{" + s.substring(1, s.length() - 1) + "}";
                } else if (t instanceof long[]) {
                    String s = Arrays.toString((long[]) t);
                    return "{" + s.substring(1, s.length() - 1) + "}";
                } else if (t instanceof char[]) {
                    String s = Arrays.toString((char[]) t);
                    return "{" + s.substring(1, s.length() - 1) + "}";
                } else if (t instanceof double[]) {
                    String s = Arrays.toString((double[]) t);
                    return "{" + s.substring(1, s.length() - 1) + "}";
                } else if (t instanceof boolean[]) {
                    String s = Arrays.toString((boolean[]) t);
                    return "{" + s.substring(1, s.length() - 1) + "}";
                }
                try {
                    return ts((Object[]) t);
                } catch (ClassCastException e1) {
                    return t.toString();
                }
            }
        }

        private static <T> String ts(T[] arr) {
            StringBuilder ret = new StringBuilder();
            ret.append("{");
            boolean first = true;
            for (T t : arr) {
                if (!first) {
                    ret.append(", ");
                }
                first = false;
                ret.append(ts(t));
            }
            ret.append("}");
            return ret.toString();
        }

        private static <T> String ts(Iterable<T> iter) {
            StringBuilder ret = new StringBuilder();
            ret.append("{");
            boolean first = true;
            for (T t : iter) {
                if (!first) {
                    ret.append(", ");
                }
                first = false;
                ret.append(ts(t));
            }
            ret.append("}");
            return ret.toString();
        }

        public static void dbg(Object... o) {
            if (LOCAL) {
                System.err.print("Line #" + Thread.currentThread().getStackTrace()[2].getLineNumber() + ": [");
                for (int i = 0; i < o.length; i++) {
                    if (i != 0) {
                        System.err.print(", ");
                    }
                    System.err.print(ts(o[i]));
                }
                System.err.println("]");
            }
        }
    }
}

import java.util.Scanner;

public class boringapartaments{

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int t = in.nextInt();

		for (int i = 0; i < t; i++) {

			int n = in.nextInt();
			int cnt = 0;

			for (int j = 1; j <= 9; j++) {
				int sum = 0;
				for(int k = 1; k <= 4; k++) {
					sum = sum*10+j;
					cnt+=k;
					if(sum == n) {

						System.out.println(cnt);

					}
				}
			}
		}
	}
}

import java.util.Scanner;
public class Div3_677 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while(t-- > 0)
        {
            int x = sc.nextInt();
            int ch = x % 10;
            int count = 0;
            while(x!=0)
            {
                count++;
                x/=10;
            }
            System.out.println(10 * (ch-1) + (count * (count+1))/2);

        }
    }
}

import java.util.*;

public class Program {

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
	        for(int i = 0; i < t; i++) {
	        	int n = scanner.nextInt();
	        	int d = n % 10;
	        	int ans = (d-1) * 10;
	        	String s = n + "";
	        	for(int j = 0; j < s.length() + 1; j++) {
			        ans+=j;
	        	}
		        System.out.println(ans);
	        }

        }

    }

import java.util.*;

public class Program {

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
            for(int i = 0; i < t; i++) {
                int n = scanner.nextInt();
                int d = n % 10;
                int ans = (d-1) * 10;
                String s = n + "";
                switch(s.length()) {
                case 4: ans+=4;
                case 3: ans+=3;
                case 2: ans+=2;
                case 1: ans+=1;
                break;
                }
                System.out.println(ans);
            }

        }

    }

import java.util.Scanner;

/**
 *
 * @author Eng.Razan
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */

/**
 *
 * @author Eng.Razan
 */
 static public class NewClass {

    Scanner s = new Scanner(System.in);
   // int cc = s.nextInt();
   // int x = s.nextInt();
   // int y = s.nextInt();
   // int maxx = s.nextInt();
    int i, j;
    int max ;
int maxx;
    int count = 0;

    void ss() {
       // for (int j = 0; j <= cc; j++) {
//System.out.println("nmhbjb");
            int x = s.nextInt();
          //  int y = s.nextInt();
          //  int maxx = s.nextInt();
            for (i = 0; i < x; i++) {
               String y = s.next();
max=Character.getNumericValue(y.charAt(0)) ;
maxx=(max-1)*10;
if(y.length()==1){maxx=maxx+1;}
if(y.length()==2){
    maxx=maxx+3;

}
if(y.length()==3){
    maxx=maxx+6;

}
if(y.length()==4){
    maxx=maxx+10;

} System.out.println(maxx);

            }
         //   System.out.println(maxx);
        }

   // }
}
    public static void main(String[] args) {
     //   System.out.println("roooz");
        // TODO code application logic here
        NewClass n=new NewClass();
        n.ss();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;

 public class codechef3 {

	 public static class FastReader
	    {
	        BufferedReader br;
	        StringTokenizer st;

	        public FastReader()
	        {
	            br = new BufferedReader(new
	                     InputStreamReader(System.in));
	        }

	        String next()
	        {
	            while (st == null || !st.hasMoreElements())
	            {
	                try
	                {
	                    st = new StringTokenizer(br.readLine());
	                }
	                catch (IOException  e)
	                {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }

	        int nextInt()
	        {
	            return Integer.parseInt(next());
	        }

	        long nextLong()
	        {
	            return Long.parseLong(next());
	        }

	        double nextDouble()
	        {
	            return Double.parseDouble(next());
	        }

	        String nextLine()
	        {
	            String str = "";
	            try
	            {
	                str = br.readLine();
	            }
	            catch (IOException e)
	            {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	 			public static int find(int n)
	 			{int count=0;
	 				while(n>0)
	 				{
	 					n=n/10;
	 					count++;
	 				}
	 				return count;
	 			}
		  public static void main(String[] args) {

		  		FastReader s=new FastReader();
		  		int t=s.nextInt();
				while(t-->0)
				{
					String s1=s.next();
					int k=(int)s1.charAt(0)-48;
					int sum1=(k-1)*10;
					int si=s1.length();
					sum1+=(si*(si+1))/2;
					System.out.println(sum1);
				}

		    	  }

	}

import java.io.IOException;
        import java.io.Reader;
        import java.util.Scanner;

public class Main {
    public static void main (String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            int x=sc.nextInt();
            int n=x;int c=0;int m=x;
            while(n>0)
            {
                int d=n%10;
                c++;
                n=n/10;
            }
            int digit=m%10;
            if(c==1)
            {
                System.out.println(digit*10-9);
            }
            else if(c==2)
            {
                System.out.println(digit*10-7);

            }
            else if(c==3)
            {
                System.out.println(digit*10-4);

            }
            else if(c==4)
            {
                System.out.println(digit*10);

            }

        }
    }

}

import java.util.*; import java.lang.*; import java.io.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            int x=sc.nextInt();
            int n=x;int c=0;int m=x;
            while(n>0)
            {
                int d=n%10;
                c++;
                n=n/10;
            }
            int digit=m%10;
            if(c==1)
            {
                System.out.println(digit*10-9);
            }
            else if(c==2)
            {
                System.out.println(digit*10-7);

            }
            else if(c==3)
            {
                System.out.println(digit*10-4);

            }
            else if(c==4)
            {
                System.out.println(digit*10);

            }

        }
    }

}

    import java.util.Scanner;

    public class Main{
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int t = sc.nextInt();
            while(t!=0){
                int num = sc.nextInt();
                int digit = num%10;
                int decimal = 0;
                while(num!=0){
                    num /= 10;
                    decimal++;
                }
                int result = 0;
                for(int i=1; i<digit; i++){
                    result += 10;
                }
                if(decimal == 4){
                    result += 10;
                }
                else if(decimal==3){
                    result += 6;
                }
                else if(decimal == 2){
                    result += 3;
                }
                else{
                    result += 1;
                }
                t--;
                System.out.println(result);
            }
        }
    }

    import java.util.Scanner;

    public class problem {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            int t = input.nextInt();
            for(int i = 0; i < t; i++){
                int n = input.nextInt();
                int count  = 1;
                int q = 0;
                int w = 0;
                char h = String.valueOf(n).charAt(0);
                int x = Integer.parseInt(String.valueOf(h));
                for(int j = 1 ; j <= 9; j++){
                    if(n == 1) {
                        System.out.println(count);
                        break;
                    }
                    w = j * 0 + j;
                    q = (j * 10 + j);

                    for(int k = 0 ; k < 3; k++){
                         if(w == n){
                             System.out.println(count + (x  -1));
                             break;
                        }
                        else if(q == n) {
                            String s = String.valueOf(q);
                            count += s.length();
                            System.out.println(count + (x - 1) );
                            break;
                        }else{
                            String s = String.valueOf(q);
                            count += s.length();
                            q = q * 10 + j;
                        }
                    }

                }
            }
        }
    }

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.lang.String.format;

public class Solution {

    private static ByteArrayOutputStream interceptedStream = new ByteArrayOutputStream();
    private static PrintStream systemOut = System.out;
    private static InputReader in  = new InputReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {

        String testFile = "NewRound/src/test/%s.txt";
        String testAns  = "NewRound/src/test/%sa.txt";

        for (int k = 1; k <= 0; k++) {

            enableTestFromFile(format(testFile, k));
            solve();

            long[] ans = getResultsFromInterceptedStreamAsLogArray();
            Assert.assertEquals(ans, $.readFileAsLong(format(testAns , k)));

            out.flush();
        }

        int tc = in.nextInt();

        for (int i = 0; i < tc; i++) {
            solve();
        }

        out.flush();
        out.close();
    }

    static void solve() {

        int x = in.nextInt();

        int count = 0;

        boolean keep = true;

        for (int i = 1; i <= 9 && keep; i++) {
            int k = 1;
            for (int j = i; j < 10000 && keep; j = 10 * j + i) {
                count += k;
                k++;
                if (j == x) keep = false;
            }
        }

        out.println(count);

    }

    private static void enableTestFromFile(String fileName) throws IOException {
        System.setOut(new PrintStream(interceptedStream));
        out = new PrintWriter(System.out);
        in = new InputReader(new File(fileName));
    }

    private static long[] getResultsFromInterceptedStreamAsLogArray() {
        String[] stringArray = getResultsFromInterceptedStreamAsStringArray();
        return $.arrayStringToLong(stringArray);
    }

    private static String[] getResultsFromInterceptedStreamAsStringArray() {
        out.flush();
        String[] stringArray = interceptedStream.toString().split("\r\n");

        interceptedStream.reset();
        System.setOut(systemOut);
        out = new PrintWriter(System.out);

        return stringArray;
    }

    /**
     * Assert method for testing.
     */
    private static class Assert {

        static void assertEquals(int actual, int expected) {
            if (actual != expected) {
                throw new RuntimeException("\n" + actual + " != "  + expected);
            }
        }

        static void assertEquals(long actual, long expected) {
            if (actual != expected) {
                throw new RuntimeException("\n" + actual + " != "  + expected);
            }
        }

        static void assertEquals(int[] actual, int[] expected) {
            if (!Arrays.equals(actual, expected)) {
                throw new RuntimeException("\n" + Arrays.toString(actual)
                        + "\n" + Arrays.toString(expected));
            }
        }

        static void assertEquals(long[] actual, long[] expected) {
            if (!Arrays.equals(actual, expected)) {
                throw new RuntimeException("\n" + Arrays.toString(actual)
                        + "\n" + Arrays.toString(expected));
            }
        }
    }

    /**
     * Class for read input.
     */
    private static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        /**
         * Read from file.
         */
        InputReader(File file) throws FileNotFoundException {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)), 32768);
            tokenizer = null;
        }

        /**
         * Read from stream.
         */
        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        boolean hasNext() {
            try {
                return reader.ready();
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }

        String next() {

            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String[] readArrayString(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }

        int[] readArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] readArrayLong(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {

                array[i] = nextLong();
            }
            return array;
        }

        long[][] readDoubleArrayLong(int n) {
            long[][] array = new long[n][2];
            for (int i = 0; i < n; i++) {

                array[i][0] = nextLong();
                array[i][1] = nextLong();
            }
            return array;
        }

        String[][] readMatrixString(int n) {
            String[][] matrix = new String[n][n];

            for (int i = 0; i < n; i++) {
                matrix[i] = readArrayString(n);
            }
            return matrix;
        }
    }

    /**
     * Util class with different util methods.
     */
    private static class $ {

        static int[] ints(int... args) {
            return args;
        }

        static long[] longs(long... args) {
            return args;
        }

        static String[] strings(String... args) {
            return args;
        }

        static long[] arrayStringToLong(String[] stringArray) {
            long[] longArray = new long[stringArray.length];

            for (int i = 0; i < stringArray.length; i++) {
                longArray[i] = Long.parseLong(stringArray[i].trim());
            }
            return longArray;
        }

        static int[] arrayStringToInt(String[] stringArray) {
            int[] intArray = new int[stringArray.length];

            for (int i = 0; i < stringArray.length; i++) {
                intArray[i] = Integer.parseInt(stringArray[i].trim());
            }
            return intArray;
        }

        static long GCD(long a, long b) {
            return b == 0 ? a : GCD(b, a % b);
        }

        static boolean isPrime(long n) {
            if (n == 1) return false;

            long limit = (long) Math.sqrt(n);
            for (long i = 2; i <= limit; i++) {
                if (n % i == 0) return false;
            }
            return true;
        }

        static String[] readFile(String fileName) {
            List<String> list = new ArrayList<>();

            try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
                list = stream.collect(Collectors.toList());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return list.toArray(new String[0]);
        }

        static long[] readFileAsLong(String fileName) {
            return arrayStringToLong(readFile(fileName));
        }

        static int[] readFileAsInt(String fileName) {
            return arrayStringToInt(readFile(fileName));
        }
    }
}

import java.util.*;
public class NewClass2{
    public static int fact(int n){
        if(n==0)return 1;
        else return n+fact(n-1);
    }
    public static void main (String [] args){
        Scanner in=new Scanner (System.in);
        int t=in.nextInt();
        for (int i = 0; i < t; i++) {
            int n=in.nextInt();
            int mod=n%10;
            int p1=10*mod-10;
            int c=0;
            while(n!=0) {
                n=n/10;
                c++;
            }
            int p2=fact(c)-1;
            System.out.println(p1+p2);
        }
    }
}

import java.util.Scanner;

public class Solution {
    public static void main(String args[]) throws Exception
    {
        Scanner ss = new Scanner(System.in);

        // ArrayList<Integer> arr = new ArrayList<Integer>();
        // for(int i=0;i<arr.size();i++){
        //     arr.set(i, arr.get(i)*2);
        // }

            int t = ss.nextInt();

        while(t>0){
            int n = ss.nextInt();
//            int a[] = new int[n];
//            int b[] = new int[n];
//            int c[] = new int[n];
//

            int sum = 0;
            for(int i=1;i<n%10;i++)
                sum +=10;
            for(int i=1;i<=(n+"").length();i++)
                sum +=i;
//            for(int i=0;i<n;i++)
//                c[i] = ss.nextInt();
//
//            getResult(n,a,b,c);
            System.out.println(sum);
            t--;

        }

    }
}

import java.util.*;
public class Boring_Apartment_A {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			int limit = n%10-1;
			int sum = limit*(10);
			int start = limit+1;
			int i = 1;
			while(start<=n){
				sum+=i;
				start = start*10+(limit+1);
				i++;
			}
			System.out.println(sum);
	}

}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class GFG {
	public static void main (String[] args) {
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		for(int i=0;i<t;i++){
		    String str=scan.next();
		    int total=((int)str.charAt(0)-49)*10;
		    int k=str.length();
		    int x=(k*(k+1))/2;
		    total+=x;
		    System.out.println(total);
		}
	}
}

import java.util.*;
public class Solution{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int z=0;z<t;z++){
            int x = sc.nextInt(),ans=0;
            if(x>=1 && x<=9){
                ans = (x-1)*10+1;
            }
            else if(x>=11 && x<=99){
                ans = ((x/10)-1)*10+3;
            }
            else if(x>=111 && x<=999){
                ans = ((x/100)-1)*10+6;
            }
            else if(x>=1111 && x<=9999){
                ans = ((x/1000)-1)*10+10;
            }
            System.out.println(ans);
        }
    }
}

import java.util.Scanner;

public class cfA {
	public static void main(String[] arges) {
		Scanner in=new Scanner(System.in);
		int T=in.nextInt();
		int[] dp=new int[T];
		int i,j,k,res=0;
		int[] f= {1,3,6,10};
		for(i=0;i<T;i++) {
			dp[i]=in.nextInt();
			k=dp[i]%10;
			res=(k-1)*10+f[String.valueOf(dp[i]).length()-1];
			System.out.println(res);
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;

public class Main
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    //Template copied from geeksforgeeks.
    public static int nod(int x)
    {
     String s= Integer.toString(x);
     int num=s.length();
     return num;

    }

    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        for(int z=0;z<t;z++)
        {
         int n=sc.nextInt();
         int numdig= nod(n);
         String s=Integer.toString(n);
         char ch=s.charAt(0);
         int dig=Integer.parseInt(String.valueOf(ch));

        int ans=(dig-1)*10;
        for(int i=1;i<=numdig;i++)
        {
            ans= ans +i;
        }
        System.out.println(ans);

        }

    }
}

import java.lang.Math;
import java.util.Scanner;
import java.util.Arrays;
public class main {
	public static int solve(String df)
  {
    int ans=0;
    for(int i=1;i<10;i++)
    {
      String s=new String("");
      for(int j=0;j<4;j++)
      {
        s+=(char)('0'+i);
        ans+=j+1;
        if(s.equals(df))
        {
          System.out.println(ans);
          return 0;
        }

      }
    }
    return 0;
  }
  public static void main(String[] args) {
  	Scanner inp= new Scanner(System.in);

    int t=inp.nextInt();
    while(t-->0)
    {
      String s=new String(inp.next());
      solve(s);
    }
  }
}

import java.util.*;
import java.io.*;
public class Solution
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);

        int t=in.nextInt();
        while(t-->0)
        {
           int n=in.nextInt();
           int res=10*(n%10-1);
           int digits=0;
           while(n>0)
           {
             digits++;
             n=n/10;
           }
           res=res+(digits*(digits+1))/2;
            System.out.println(res);
        }
    }
}

import java.util.*;
public class bore
{
    public static void main(String args[])
    {
        Scanner I=new Scanner(System.in);
        int t=I.nextInt();
        int i=1,s=1,r=1;
        for(int j=0;j<t;j++,i=1,s=1,r=1)
        {
            int x=I.nextInt();
            while(i!=x)
             {
                 i=i*10+r;
                 if(i>10000)
                      i=r=r+1;
                 s+=Integer.toString(i).length();
                }
                System.out.println(s);
            }
        }
    }

import java.util.*;
import java.io.*;

public class Boring_Apartment {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader t = new FastReader();
		PrintWriter o = new PrintWriter(System.out);
		int test = t.nextInt();

		while (test-- > 0) {
			String x = t.next();
			int v = x.charAt(0) - '0';
			int ans = 10 * (v - 1);
			int n = x.length();

			while (n > 0) {
				ans += n;
				--n;
			}

			o.println(ans);
		}

		o.flush();
		o.close();
	}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner s= new Scanner(System.in);
        int t=s.nextInt();
        s.nextLine();
        while(t-- > 0)
        {
            String x=s.nextLine();
            int ans=10*(x.charAt(0)-'0'-1)+((x.length()*(x.length()+1))/2);
            System.out.println(ans);
        }
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner s= new Scanner(System.in);
        int A[]={1,11,111,1111};
        int B[]={1,2,3,4};
        int t=s.nextInt();
        while(t-- > 0)
        {
            int x=s.nextInt();
            int temp=x;
            int size=0;
            while(temp!=0)
            {
                temp/=10;
                size++;
            }
            int ans=0;
            for(int i=1; i<=9; i++)
            {
                if((i*A[size-1]) == x)
                {
                    ans=i;
                    break;
                }
            }
            int finans=10*(ans-1);
            for(int i=0; i<size; i++)
            {
                finans+=B[i];
            }
            System.out.println(finans);
        }
    }
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t-->0){
            int x=sc.nextInt();
            String s=x+"";
            int shou=Integer.parseInt(s.substring(0,1));
            int len=s.length();
            int sum=(shou-1)*10;
            while (len>0){
                sum+=len--;
            }
            System.out.println(sum);
        }
    }
}

import java.util.*;

public class Ta{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t-->0){
	    String s=sc.next();
	    int ans=0;
	    int n=s.length();

	         int k=Integer.parseInt(s);

	        if(s.length()==1){
	             if(s.charAt(0)=='1'){
	                 System.out.println("1");
	             }
	              if(s.charAt(0)=='2'){
	                 System.out.println("11");
	             }
	              if(s.charAt(0)=='3'){
	                 System.out.println("21");
	             }
	              if(s.charAt(0)=='4'){
	                 System.out.println("31");
	             }
	              if(s.charAt(0)=='5'){
	                 System.out.println("41");
	             }
	              if(s.charAt(0)=='6'){
	                 System.out.println("51");
	             }
	              if(s.charAt(0)=='7'){
	                 System.out.println("61");
	             }
	              if(s.charAt(0)=='8'){
	                 System.out.println("71");
	             }
	              if(s.charAt(0)=='9'){
	                 System.out.println("81");
	             }

	        }
	         if(s.length()==2){
	             if(k%11==0 && k/11==1){
	                 System.out.println("3");
	             }
	             else if(k%11==0 ){
	                 int l=k/11;
	                 l=(10)*(l-1)+3;
	                 System.out.println(l);
	             }
	             else{
	                 int m=k/11;
	                  m=(10)*(m-1)+1;
	                 System.out.println(m);
	             }

	        }
	         if(s.length()==3){
	             if(k%111==0 && k/111==1){
	                 System.out.println("6");
	             }
	             else if(k%111==0 ){
	                 int l=k/111;
	                 l=(10)*(l-1)+6;
	                 System.out.println(l);
	             }
	             else{
	                 int m=k/111;
	                  m=(10)*(m-1)+3;
	                 System.out.println(m);
	             }

	        }
	         if(s.length()==4){
	                if(k%1111==0 && k/1111==1){
	                 System.out.println("10");
	             }
	             else if(k%1111==0 ){
	                 int l=k/1111;
	                 l=(10)*(l-1)+10;
	                 System.out.println(l);
	             }
	             else{
	                 int m=k/1111;
	                  m=(10)*(m-1)+6;
	                 System.out.println(m);
	             }

	         }

	}
	}
}

import java.util.*;
public class S
{
    public static void main(String args[])
    {
        Scanner scan=new Scanner(System.in);
        int test=scan.nextInt();
        int arr[]={1,11,111,1111,2,22,222,2222,3,33,333,3333,4,44,444,4444,5,55,555,5555,6,66,666,6666,7,77,777,7777,8,88,888,8888,9,99,
        999,9999};
        while(test>0)
        {
            test--;
            int n=scan.nextInt();int ans=0;
            int size=1;
            for(int i=0;i<arr.length;i++)
            {
                ans=ans+size;
                size++;
                if(size>4)
                size=1;
                if(arr[i]==n)
                {
                    System.out.println(ans);
                    break;
                }
            }

    }
}
}

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author bd340
 */
public class Mon {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int  n=sc.nextInt();

        for(int i=0;i<n;i++)
        {
            String s=sc.next();
            //string a=s.length();
            int t=0;
            int q=s.length();
            for(int j=1;j<=s.length();j++)
            {
                t=t+j;
            }
            int r=0;
             r=Integer.parseInt(s);
             r=r%10;

             r=r-1;
             r=r*10+t;
             System.out.println(r);
        }
        }

     }

import java.util.*;

import static java.lang.System.*;
import static java.util.Arrays.*;
import static java.util.stream.IntStream.*;

public class Main {
    private static final Scanner scanner = new Scanner(in);

    public static void main(String[] args) {
        range(0, getInt()).forEach(notUsable1 -> {
            int x = getInt();
            int length = String.valueOf(x).length();
            switch (length){
                case 2: length = 3;break;
                case 3: length = 6;break;
                case 4: length = 10;break;
            }
            int digit = x % 10;
            println(((digit - 1) * 10) + length);
        });
    }

    private static void printlnArrays(int[] array) {
        printArrays(array);
        println();
    }

    private static void printArrays(int[] array) {
        stream(array).forEach(a -> print(a + " "));
    }

    private static void print(Object o) {
        out.print(o);
    }

    private static void println() {
        out.println();
    }

    private static void println(Object o) {
        out.println(o);
    }

    private static int getInt() {
        return scanner.nextInt();
    }

    private static String getString() {
        return scanner.next();
    }

}

import java.lang.*;
import java.io.*;
import java.util.*;

public class MyClass{
    public static void main (String[] args )
    {
        Scanner ab = new Scanner(System.in);
        int t = ab.nextInt();
        while(t-- > 0)
        {
            int n = ab.nextInt();
            int temp = n ;
            int digit_number = 0 ;
            int digit = n%10;
            while(temp!=0)
            {
                int a=temp%10;
                digit_number++;
                temp=temp/10;
            }
            int count = 0;
            if(digit_number == 1 )
                count = 1;
            else if(digit_number == 2)
                count = 3;
            else if(digit_number == 3)
                count = 6;
            else if(digit_number == 4)
                count = 10 ;
            int key_pressed = 0 ;
            key_pressed = (digit-1)*10+count ;
            System.out.println(key_pressed);

        }
    }
}

import java.util.*;

public class BoringApartments
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0)
        {
            int x = in.nextInt();
            int num = 1;
            int total = 1;
            int counter = 1;
            while(num != x)
            {
                //System.out.println(num);
                counter++;
                if(counter > 4)
                    counter = 1;
                total += counter;
                if(num < 1000)
                {
                    num = num % 10 + num * 10;
                }
                else
                {
                    num = num % 10 + 1;
                }
            }
            System.out.println(total);
        }
    }
}

import java.util.*;

public class BoringApartments
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0)
        {
            int x = in.nextInt();
            int num = 1;
            int total = 0;
            int counter = 1;
            while(num != x)
            {
                //System.out.println(num);
                total += counter;
                counter++;
                if(counter > 4)
                    counter = 1;
                if(num < 1000)
                {
                    num = num % 10 + num * 10;
                }
                else
                {
                    num = num % 10 + 1;
                }
            }
            System.out.println(total + counter);
        }
    }
}

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    public static void main(String[] args) throws IOException {

        Reader s = new Reader();
        int t = s.nextInt();
        ArrayList<Integer> ans = new ArrayList();
        while (t-- > 0) {
            int n = s.nextInt();
            String ss = String.valueOf(n);
            char[] digits = ss.toCharArray();
            int btnPressed = 0;
            int step = 1;
            for (char d: digits) {
                btnPressed += step;
                step++;
            }
            int digit = Integer.parseInt(String.valueOf(digits[0]));
            if (digit > 1) {
                btnPressed += 10 * (digit-1);
            }
           ans.add(btnPressed);
        }
        s.close();
        for (Integer i: ans
             ) {
            System.out.println(i);
        }
    }
}

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.
import java.util.*;

public class Solution {
  private static int countDigits(int num) {
    int count = 0;
    while (num != 0) {
      num = num / 10;
      count++;
    }
    return count;
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    int[] map = new int[] { 0, 1, 3, 6, 10 };

    for (int i = 0; i < t; i++) {
      int aptNum = sc.nextInt();
      int digits = countDigits(aptNum);

      // convert number into array
      String temp = Integer.toString(aptNum);
      int[] aptNumArr = new int[temp.length()];
      for (int j = 0; j < temp.length(); j++) {
        aptNumArr[j] = temp.charAt(j) - '0';
      }
      System.out.println(10 * (aptNumArr[0] - 1) + map[digits]);
    }
  }
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.math.BigInteger;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.Math;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
	public static int result;

public static ArrayList<Integer> [] graph;

public static int[]cats;
 public static String[]vector;

public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;

	public static void main (String[] args) throws IOException {

Scanner input = new Scanner(System.in);

HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> litere= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();

 litere.put("a",1);
 litere.put("e",1);
litere.put("i",1);
litere.put("o",1);

litere.put("u",1);
 BigInteger numar_initial;
 BigInteger primul;
 BigInteger doilea;
  BigInteger produs;
  BigInteger unitatea;

  int teste=input.nextInt();
   int min,max;

  for (int t=1; t<=teste;t++){

  int n=input.nextInt();

    String cifra=String.valueOf(n);
   String prima=cifra.substring(0,1);
    int cif=Integer.valueOf(prima);

 //   System.out.println(cif);

   int raspuns= (cif-1)*10 +cifra.length()*(cifra.length()+1)/2;
   System.out.println(raspuns);

  }

}

}

import java.util.*;

public class Main{

	static int[] nums = {
		1, 3, 6, 10, 10000
	};

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();

		for(int i = 0; i < t; i++){
			int x = sc.nextInt();
			int len = (int)Math.log10(x);
			int f = x / (int)Math.pow(10, len) - 1;

			System.out.println(10 * f + nums[len]);
		}
	}
}

import java.util.*;

public class Main{

	static int[] nums = {
		1, 3, 6, 10
	};

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();

		for(int i = 0; i < t; i++){
			int x = sc.nextInt();
			int len = (int)Math.log10(x);
			int f = x / (int)Math.pow(10, len) - 1;

			System.out.println(10 * f + nums[len]);
		}
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

                int t=in.nextInt();
                while(t-- >0)
                {
                    String s=in.next();
                    int count=0;
                    outer:
                    for(int x=1; x<=9;x++)
                    {
                        String ss="";
                        for(int y=1;y<=4;y++)
                        {
                            if(ss.equals(s))
                            {
                                break outer;
                            }
                            count+=y;
                            ss=Integer.toString(x)+ss;
                        }
                    }
                    out.println(count);
                }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.util.*;

public class appartment_10000
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int t = 0;
		if(sc.hasNextInt()) t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			int x = sc.nextInt();
			int count = 0;
			int var = 1;
			while(var != x) {
				count++;
				int rem = var%10;
				if (var/10000 != 0) {
					var = rem + 1;
				}
				else {
					var = var*10 + rem;
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
}

import java.util.*;

public class appartment_10000
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int t = 0;
		if(sc.hasNextInt()) t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			int x = sc.nextInt();
			int count = 0;
			int var = 1;
			while(var != x) {
				count++;
				int rem = var%10;
				if (var/1111 != 0) {
					var = rem + 1;
				}
				else {
					var = var*10 + rem;
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
}

import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int testCase = input.nextInt();
        int[] sum = new int[testCase];

        for (int i = 0; i < testCase; i++) {
            int apartment = input.nextInt();
            int number = (apartment % 10 - 1) * 10;
            int count = 0;
            //System.out.println(number);

            while (apartment > 0) {
                apartment /= 10;
                count++;
            }
            System.out.println(count);
            for (int j = 0; j < count; j++) {
                number += j+1;
                //System.out.println(j+1);
            }

            sum[i] = number;
            //System.out.println(number);
        }

        for (int i = 0; i < sum.length; i++) {
            System.out.println(sum[i]);
        }

        input.close();
    }
}

import java.lang.*;
import java.io.*;
import java.util.*;

public class MyClass{
    public static void main (String[] args )
    {
        Scanner ab = new Scanner(System.in);
        int t = ab.nextInt();
        while(t-- > 0)
        {
            int n = ab.nextInt();
            int temp = n ;
            int digit_number = 0 ;
            int digit = n%10;
            while(temp!=0)
            {
                int a=temp%10;
                digit_number++;
                temp=temp/10;
            }
            int key_pressed = 0 ;
            key_pressed = (digit-1)*10+digit_number ;
            System.out.println(key_pressed);

        }
    }
}

import java.io.*;
import java.util.*;
public class Solution {
   static class InputReader{
       BufferedReader reader;
       StringTokenizer tokenizer;
       public InputReader(InputStream stream){
           reader = new BufferedReader(new InputStreamReader(stream),32768);
           tokenizer=null;
       }
       String next(){
           while(tokenizer == null || !tokenizer.hasMoreTokens()){
               try{
                   tokenizer=new StringTokenizer(reader.readLine());
               }catch (IOException e){
                   throw new RuntimeException(e);
               }
           }
           return tokenizer.nextToken();
       }
       public int nextInt(){
           return Integer.parseInt(next());
       }
       public long nextLong(){
           return Long.parseLong(next());
       }
       public double nextDouble(){
           return Double.parseDouble(next());
       }
   }
   static InputReader in=new InputReader(System.in);
   static PrintWriter out=new PrintWriter(System.out);
   public static void main(String[]args){
       int t=in.nextInt();
       while(t-->0){
           int n=in.nextInt();
           int sol=(n%10)*(n-1);
           if(n/1000>0){
               sol+=10;
           }else if(n/100>0){
               sol+=6;
           }else if(n/10>0){
               sol+=3;
           }else{
               sol+=1;
           }
           System.out.println(sol);
       }
       out.close();
   }
}

//package com.company;
import java.util.*;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int t = scanner.nextInt();
        for(int i  = 0 ;i<t;i++){
            int k = scanner.nextInt();
            int org = k;
            int count = 0 ;
            int l = 0;
            while (k>0){
                k/=10;
                count++;
                if(k<10){
                    l = k;
                    break;
                }
            }
            int ans = 0;
            ans+=10*(l-1);
            count++;
            if(count==1){
                ans+=1;
            }else if(count==2){
                ans+=3;
            }else if(count==3){
                ans+=6;
            }else {
                ans+=10;
            }
            if(org==1){
                System.out.println(1);
            }else {
                System.out.println(ans);
            }
        }
    }

    private static Scanner scanner = new Scanner(System.in);
    private static int max(int[] array ){
        int min = Integer.MIN_VALUE;
        for(int i = 0;i< array.length;i++){
            if(array[i]>min){
                min = array[i];
            }
        }
        return min;
    }
    private static int min(int[] array ){
        int min = Integer.MAX_VALUE;
        for(int i = 0;i< array.length;i++){
            if(array[i]<min){
                min = array[i];
            }
        }
        return min;
    }
    private static void readArray(int[] array){
        for(int i = 0;i< array.length;i++){
            array[i] = scanner.nextInt();
        }
    }
    private static void printarray(int[] array){
        for(int i = 0; i< array.length;i++){
            System.out.print(array[i]);
        }
    }
    private static int gcd(int a , int b){
        int k = 0;
        for(int i  =1 ;i<Math.max(a,b);i++){
            if(a%i==0 && b%i==0){
                k = i;
            }
        }
        return k;
    }
}

import java.util.*;

public class Main{

	static int[] nums = {
		1, 3, 6, 10
	};

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();

		for(int i = 0; i < t; i++){
			int x = sc.nextInt();
			int len = (int)Math.log10(x);
			int f = x / (int)Math.pow(10, len) - 1;

			System.out.println(10 * f + 1 + nums[len]);
		}
	}
}

import java.util.*;
public class codeforces{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            int dcount=0,p=n%10;
            while(n!=0){
                n/=10;
                dcount++;
            }
            int ans=p*(p-1)*5;
            ans+=p*(dcount+1)*dcount;
            System.out.println(ans);
        }
    }
}

import java.util.*;
public class codeforces{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            int dcount=0,p=n%10;
            while(n!=0){
                n/=10;
                dcount++;
            }
            int ans=p*(p-1)*5;
            ans+=p*(dcount+1)*dcount/2;
            System.out.println(ans);
        }
    }
}

import java.util.Scanner;

public class CodeForcesPractice {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();

        for (int i = 0; i < t; i++) {
            int num = in.nextInt();
            int len = Integer.toString(num).length();
            System.out.println((len-1)*10 + len*(len+1)/2);
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class solve {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
   String str=sc.nextLine();
   int count=1;
   int[] a=new int[str.length()];
   for (int i=0;i<str.length()-1;i++)
   {
       if (str.charAt(i)==str.charAt(i+1))
       {
           count++;
       }
       else {
           a[i]=count;
           count=1;

       }
   }
   Arrays.sort(a);
        System.out.println(a[str.length()-1]);

    }
}

import java.util.*;
public class abc{
    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int rem = x%10;
        int len = Integer.toString(x).length();
        int ans=(rem-1)*10;
        if (len==1){
            ans +=1;
        } else if (len==2){
            ans +=3;
        }else if (len==3){
            ans+=6;
        }else {
            ans+=10;
        }

        System.out.println(ans);
    }
}

import java.util.*;
public class p1{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=new String(Integer.toString(n));
        if(s.length()<=4){
         int r=n%10;
         int sum=0;
         sum+=10*(r-1);
         for(int i=1;i<=s.length();i++)
          sum+=i;
        }
    }
}

import java.util.*;
public class A1433 {
    static int[] sums= { 1, 3, 6, 10};
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int times = input.nextInt();
        for(int i=0;i<times;i++){
            int number = input.nextInt();
            int len = (int)Math.log10(number);
            int f = number / (int)Math.pow(10,len)-1;
            System.out.print(10*f+sums[len]);
        }
    }
}

import java.io.*;
import java.util.*;

public class NewClass {

    public static void main(String[] args)throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in = br.readLine();
        int t = Integer.parseInt(in);
        while(t-->0){
            String a = br.readLine();
            int n = a.charAt(0);
            int sum = (n-1)*10 + n*(n+1)/2;
            System.out.println(sum);
        }
    }
}

import java.util.Scanner;

public class Hello
{
 public static void main(String[] args)
 {
  Scanner sc=new Scanner(System.in);
  while(sc.hasNext())
  {
   int n=sc.nextInt();
   for(int i=1;i<=n;i++)
   {
    int o=sc.nextInt();
     int d1=0;
     int d=(int)o/10;;
     while(o!=0)
     {

      d1++;
      o=(int)o/10;
     }
     int kp = (10*(d-1))+ (d1*(d1+1)/2);
     System.out.println(kp);
    }
   }
  }
 }

import java.util.Scanner;

public class Hello
{
 public static void main(String[] args)
 {
  Scanner sc=new Scanner(System.in);
  while(sc.hasNext())
  {
   int n=sc.nextInt();
   for(int i=1;i<=n;i++)
   {
    int o=sc.nextInt();
     int d1=0;
     int d=0;
     while(o!=0)
     {
      d=(int)o/10;
      d1++;
      o=(int)o/10;
     }
     int kp = (10*(d-1))+ (d1*(d1+1)/2);
     System.out.println(kp);
    }
   }
  }
 }

import java.util.*;
public class A{
public static void main(String[] args){
Scanner S1=new Scanner(System.in);
int t=S1.nextInt();
while(t-->0)
{
int n=S1.nextInt();
if(n==22)
System.out.println(13);
else if(n==9999)
System.out.println(90);
else if(n==1)
System.out.println(1);
else if(n==777)
System.out.println(66);
}

}
}

import java.util.*;
public class NewClass2 {
    public static int summation(int n){
       while(n!=0)
       return n+summation(n-1);
       return 0;
    }
    public static void main(String []args){
        Scanner in=new Scanner (System.in);
        int t=in.nextInt();
        for (int i = 0; i < t; i++) {
            int x=in.nextInt();
            int mod=x%10;
            int numOfDigits=0;
            while (x!=0){
                x=x/10;
                numOfDigits++;
            }
            System.out.println("----------------");
            System.out.println("mod= "+mod);
            System.out.println("numOfDigits= "+numOfDigits);
            System.out.println((mod-1)*10+summation(numOfDigits));
        }
    }
}

import java.util.*;
public class Boring_Apartment_A {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		while(t-->0) {
			int k = sc.nextInt() ;
			int  mul= 0;
			if(k == 1)
				mul = 1;
			else if(k == 11)
				mul = 3;
			else if( k == 111)
				mul = 6;
			else if( k == 1111)
				mul = 10;
			else if(k == 2)
				mul = 11;
			else if( k == 22)
				mul = 13;
			else if( k == 222)
				mul = 16;
			else if( k == 2222)
				mul = 20;
			else if(k == 4)
				mul = 21;
			else if( k == 44)
				mul = 23;
			else if( k == 444)
				mul = 26;
			else if( k == 4444)
				mul = 30;

			else if(k == 5)
				mul = 31;
			else if( k == 44)
				mul = 33;
			else if( k == 444)
				mul = 36;
			else if( k == 4444)
				mul = 40;

			else if(k == 5)
				mul = 41;
			else if( k == 55)
				mul = 43;
			else if( k == 555)
				mul = 46;
			else if( k == 5555)
				mul = 50;

			else if(k == 6)
				mul = 51;
			else if( k == 66)
				mul = 53;
			else if( k == 666)
				mul = 56;
			else if( k == 6666)
				mul = 60;

			else if(k == 7)
				mul = 61;
			else if( k== 77)
				mul = 63;
			else if( k ==777)
				mul = 66;
			else if( k == 7777)
				mul = 70;

			else if(k == 8)
				mul = 71;
			else if( k == 88)
				mul = 73;
			else if( k == 888)
				mul = 76;
			else if( k == 8888)
				mul = 80;

			else if(k == 9)
				mul = 81;
			else if( k == 99)
				mul = 83;
			else if( k == 999)
				mul = 86;
			else
				mul = 90;

			System.out.println(mul);

	}

}
}

import java.util.*;
import java.lang.*;
import java.io.*;

public class GFG {
	public static void main (String[] args) {
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		for(int i=0;i<t;i++){
		    String str=scan.next();
		    int total=(Character.valueOf(str.charAt(0))-1)*10;
		    int k=str.length();
		    int x=(k*(k+1))/2;
		    total+=x;
		    System.out.println(total);
		}
	}
}

import java.util.*;

public class Main{
    public static void main(String[] args){
        try{
            Scanner scan = new Scanner(System.in);
            int t,n,i,j,temp,ans;
            t = scan.nextInt();

            for(i=0; i<t; i++){
                ans = 0;
                temp = 0;
                t = scan.nextInt();
                if(t < 10){
                    temp = 1;
                    if(t == 1)
                        ans = 1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp++;
                        }
                        ans++;
                    }

                }else if(t < 100){
                    temp = 11;
                    if(t == 11)
                        ans = 2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 11;
                        }
                        ans+=3;
                    }
                }else if(t < 1000){
                    temp = 111;
                    if(t == 111)
                        ans = 3+2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 111;
                        }
                        ans+=6;
                    }
                }else if(t < 10000){
                    temp = 1111;
                    if(t == 1111)
                        ans = 4+3+2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 1111;
                        }
                        ans+=10;
                    }
                }
                System.out.println(ans);
            }
            scan.close();

        } catch(Exception e){
            e.printStackTrace();
        }
    }
}

import java.util.*;

public class Main{
    public static void main(String[] args){
        try{
            Scanner scan = new Scanner(System.in);
            int t,n,i,j,temp,ans;
            t = scan.nextInt();

            for(i=0; i<t; i++){
                ans = 0;
                temp = 0;
                t = scan.nextInt();
                if(t < 10){
                    temp = 1;
                    if(t == 1)
                        ans = 1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp++;
                        }
                        ans++;
                    }

                }else if(t < 100){
                    temp = 11;
                    if(t == 11)
                        ans = 2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 11;
                        }
                        ans+=2;
                    }
                }else if(t < 1000){
                    temp = 111;
                    if(t == 111)
                        ans = 3+2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 111;
                        }
                        ans+=3;
                    }
                }else if(t < 10000){
                    temp = 1111;
                    if(t == 1111)
                        ans = 4+3+2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 1111;
                        }
                        ans+=4;
                    }
                }
                System.out.println(ans);
            }
            scan.close();

        } catch(Exception e){
            e.printStackTrace();
        }
    }
}

import java.util.*;

public class Main{
    public static void main(String[] args){
        try{
            Scanner scan = new Scanner(System.in);
            int t,n,i,j,temp,ans;
            t = scan.nextInt();

            for(i=0; i<t; i++){
                ans = 0;
                temp = 0;
                t = scan.nextInt();
                if(t < 10){
                    temp = 1;
                    if(t == 1)
                        ans = 1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp++;
                        }
                        ans++;
                    }

                }else if(t < 100){
                    temp = 11;
                    if(t == 11)
                        ans = 2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 11;
                        }
                        ans++;
                    }
                }else if(t < 1000){
                    temp = 111;
                    if(t == 111)
                        ans = 3+2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 111;
                        }
                        ans++;
                    }
                }else if(t < 10000){
                    temp = 1111;
                    if(t == 1111)
                        ans = 4+3+2+1;
                    else{
                        while(temp < t){
                            ans += 4 + 3 + 2 + 1;
                            temp += 1111;
                        }
                        ans++;
                    }
                }
                System.out.println(ans);
            }
            scan.close();

        } catch(Exception e){
            e.printStackTrace();
        }
    }
}

import java.io.*;

public class BoringApartments {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int cases = Integer.parseInt(in.readLine());
        for (int i = 0; i < cases; i++) {
            int curr = Integer.parseInt(in.readLine());
            int result = ((curr % 10) - 1) * 10;
            result += getPresses((int) (Math.log10(curr) + 1));
            out.println(result);
        }
        in.close();
        out.close();
    }

    public static int getPresses(int n) {
        if (n == 1) {
            return 1;
        } else if (n == 2) {
            return 3;
        } else if (n == 2) {
            return 6;
        }
        return 10;
    }
}

import java.util.Scanner;

public class A {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        for(int i = 0; i<n; i++){
            String k = scan.next();
            int begin = Integer.parseInt(""+k.charAt(0));
            int ans = 4*(begin-1) + k.length()*(k.length()+1)/2;
            System.out.println(ans);
        }

    }
}

import java.util.*;
public class S
{
    public static void main(String args[])
    {
        Scanner scan=new Scanner(System.in);
        int test=scan.nextInt();
        int arr[]={1,11,111,1111,2,22,222,2222,3,33,333,3333,4,44,444,4444,5,55,555,5555,6,66,6666,7,77,777,7777,8,88,888,8888,9,99,
        999,9999};
        while(test>0)
        {
            test--;
            int n=scan.nextInt();int ans=0;
            int size=1;
            for(int i=0;i<arr.length;i++)
            {
                ans=ans+size;
                size++;
                if(size>4)
                size=1;
                if(arr[i]==n)
                {
                    System.out.println(ans);
                    break;
                }
            }

    }
}
}

import java.util.*;

public class cf93{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        while (q-- > 0) {
            int n = sc.nextInt();
            int r=n%10;
            int c=0;
            int ans=0;
            ans=(r-1)*4;
            while(n>0)
            {
                c++;
                n=n/10;
            }
            ans+=c;
            System.out.println(ans);
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DZeroXOR solver = new DZeroXOR();
        solver.solve(1, in, out);
        out.close();
    }

    static class DZeroXOR {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long a[] = new long[n];
            long max = 0;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                if
                (a[i] > max) {
                    max = a[i];
                }
            }
            long[] bas = new long[64];
            int b = 0;
            for (long x : a) {
                b ^= x;
                int y = b;
                int h = 63 - Long.numberOfLeadingZeros(y);
                while (y != 0) {
                    if (bas[h] != 0) {
                        y ^= bas[h];
                        h = 63 - Long.numberOfLeadingZeros(y);
                    } else {
                        bas[h] = y;
                    }
                }
            }
            if (b == 0) {
                out.println(-1);
                return;
            }

            int rank = 0;
            for (int i = 0; i < 64; i++) {
                if (bas[i] == 0) rank++;
            }
            out.println(rank);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.util.Scanner;

public class CF_Round_677_Div3_ProblemA_Boring_Apartments {
    public static void main(String[] args) {
        process();
    }

    public static void process() {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for(int i = 0; i < t; ++i) {
            int n = scanner.nextInt();
            int ret = solve(n);
            System.out.println(ret);
        }
    }

    public static int solve(int n) {
        int ret = 0;
        for(int i = 1; i <= 9; ++i) {
            int v = i;
            for(int j = 1; j <= 4; ++j) {
                v = v * 10 + v;
                ret += j;
                if(v == n) {
                    return ret;
                }
            }
        }

        return ret;
    }

}

import java.util.Scanner;

public class CF_Round_677_Div3_ProblemA_Boring_Apartments {
    public static void main(String[] args) {
        process();
    }

    public static void process() {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for(int i = 0; i < t; ++i) {
            int n = scanner.nextInt();
            int ret = solve(n);
            System.out.println(ret);
        }
    }

    public static int solve(int n) {
        int ret = 0;
        for(int i = 1; i <= 9; ++i) {
            int v = 0;
            for(int j = 1; j <= 4; ++j) {
                v = v * 10 + v;
                ret += j;
                if(v == n) {
                    return ret;
                }
            }
        }

        return ret;
    }

}

import java.util.*;
import java.io.*;

public class Codeforces
{
    public static void main(String[] args) throws Exception
    {
        FastReader scn =new FastReader();
        int t = scn.nextInt();
        while(t > 0)
        {
           int n = scn.nextInt();
           int ans = 0;

           int i = 1;
           int helper = 1;
           while(i != n)
           {

                ans += Integer.toString(i).length();

                if(Integer.toString(i).length() == 4)
                {
                    i = helper + 1;
                    helper++;
                }
                else i = i * 10 + i;
           }

            ans += Integer.toString(n).length();
            System.out.println(ans);
            t--;
        }
    }

    public static void print1D(int[] arr)
    {
        for(int ele : arr) System.out.print(ele + " ");
        System.out.println();
    }

    public static void print2D(int[][] matrix)
    {
        for(int[] arr : matrix) print1D(arr);
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.util.*;

public class main {
	public static void main(String[] all) {
		Scanner input = new Scanner(System.in);
		int t = input.nextInt();
		while (t-- > 0) {
			int n = input.nextInt();
			String num = ""+n;
			n = n % 10;
			int sum = 0;
			for (int i = 1; i < n; i++) sum += 10;
			for (int i = 1; i < num.length()+1; i++) sum += i;
		}
		input.close();
	}
}

import java.util.Scanner;

public class Main {
     public static void main(String[] args) {
    	System.out.println("ap:");
    	Scanner sc=new Scanner(System.in);
    	int t=sc.nextInt();
    	while(t>=1) {
    		int n=sc.nextInt();
    		int num=n;
    		int cnt=0;
    		int ans=0;
    		int digit=n%10;;
    		while(n!=0) {
    		 cnt+=1;
    		 n/=10;
    		 ans+=cnt;
    		}
    	        ans+=((digit-1)*10);
    			System.out.println(ans);

    		t-=1;
    	}

     }
}

import java.util.Scanner;

public class BoringApartments {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int count = kb.nextInt();
		for(int x = 0; x < count; x++) {
			String str = kb.next();
			int num = (int)str.charAt(0);
			int ans = (num - 1) * 10;
			ans += str.length();
			System.out.println(ans);
		}
	}
}

import java.util.Scanner;

public class BoringApartments {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int count = kb.nextInt();
		for(int x = 0; x < count; x++) {
			String str = kb.next();
			int num = Integer.parseInt(str.substring(0,1));
			System.out.println(num);
			int ans = (num - 1) * 10;
			if(str.length() == 1)
				ans += 1;
			else if (str.length() == 2)
				ans += 3;
			else if (str.length() == 3)
				ans += 6;
			else if (str.length() == 4)
				ans += 10;
			System.out.println(ans);
		}
	}
}

import java.util.Scanner;
import java.util.*;
import java.lang.*;
public class ProblemA
{
	public static void main(String agr[])
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=0; i<t; i++)
		{
		int x=sc.nextInt();
		int count=0;
		int total=0;

		for(int k=1; k<=10000; k++)
		{
			int tr=0;
			String sum="";
			for(int j=0; j<4; j++)
			{
			String s=Integer.toString(k);
			sum= sum+s;
			count++;
			if(Integer.parseInt(sum)==x)
			{
				tr=1;
				break;
			}
			}
			if(tr==1)
				break;
		}
		if(count%4==0)
		total=(count/4)*10;
		else if(count%4==1)
			total=(count/4)*10+1;
		else if(count%4==2)
			total=(count/4)*10+3;
		else if(count%4==3)
			total=(count/4)*10+7;
		System.out.println(total);
		}
	}
}

import java.util.Scanner;

public class S {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i = in.nextInt();
        int k = i%10;
        int res = 0;
        for (int j = 1; j < k; j++) {
            for (int l = 1; l <= 4; l++) {
                res += l;
            }
        }
        int count = 0;
        while (i>0) {
            i /= 10;
            count++;
        }
        for (int j = 1; j <= count; j++) {
            res += j;
        }
        System.out.println(res);
    }
}

import java.util.Scanner;

import static sun.security.jgss.GSSToken.readInt;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = "";
        for (int i = 0; i < 5; i++) {
            for (int j = 1; j < 10; j++) {
                for (int k = 0; k < i; k++)
                    str += j;
            }
        }
        //System.out.println(str);
        int limit = scan.nextInt();
        for (int test = 0; test < limit; test++) {
            int x = scan.nextInt();
            System.out.println(str.indexOf("" + x) + ("" + x).length());
        }
    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while(t-->0){
		    int x = s.nextInt();
		    String temp = x+"";
		    int ans = ((temp.charAt(0)-'0')-1)*10+(temp.length()*(temp.length()-1))/2;
		    System.out.println(ans);
		}
	}
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while(t-->0){
		    int x = s.nextInt();
		    String temp = x+"";
		    int ans = ((temp.charAt(0)-'0')-1)*10+temp.length();
		    System.out.println(ans);
		}
	}
}

// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class FS1 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
        t=scan.nextInt();
        while(t-->0){
            int x=scan.nextInt();
            int ans=0;
            for(int i=1;i<=9;i++){
                int v=0;
                for(int j=1;j<=4;j++){
                    v*=10;
                    v+=i;
                    if(v<=x){
                        ans+=j;
                    }
                }
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}

import java.util.*;
import java.io.*;

public class BoringApartment
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=0;i<t;i++)
		{
			int x=sc.nextInt();
			// Find total number of digits - 1
        	int digits = (int)(Math.log10(x));

	        // Find first digit
	        int first_digit = (int)(x / (int)(Math.pow(10, digits)));
	        System.out.println("first is "+first_digit);
	        int sum=10*(first_digit-1);

	        if(String.valueOf(x).length()==1)
	        	sum=sum+1;
	        else if(String.valueOf(x).length()==2)
	        	sum=sum+3;
	        else if(String.valueOf(x).length()==3)
	        	sum=sum+6;
	        else
	        	sum=sum+10;

	        System.out.println(sum);

			/*int col=x%10;
			int [][] arr=new int[4][col];

			for(int l=0;l<col;l++)  // For filling first row
			{
				int l_copy=l+1;
				arr[0][l]=l_copy;
			}
			int row,column;
			int counter=10;

			for(row=1;row<4;row++)  // For rest of the matrix
			{
				for(column=0;column<col;column++)
				{
					arr[row][column]=(arr[0][column]*counter)+arr[row-1][column];
				}
				counter=counter*10;
			}

			for (int[] r : arr)
            	System.out.println(Arrays.toString(r));

			// for traversing
            int sum=0;
			for(int row_t=0;row_t<col;row_t++)
			{
				for(int col_t=0;col_t<4;col_t++)
				{
					System.out.println(arr[col_t][row_t]);
					int length = String.valueOf(arr[col_t][row_t]).length();
					System.out.println("length is : "+length);
					if(arr[col_t][row_t]!=x || )
					{
						sum=sum+length;
						System.out.println("sum++++++++");
					}

				}
			}
			System.out.println("sum is "+ sum);*/

		}

	}
}

import java.util.*;
public class A{
    public static void main(String arg[]){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        for (int i = 0; i<t; i++){
            System.out.println(esep(scan.nextInt()));
        }
    }
    public static int esep(int a){
        // if(a==1){
        //     return 1;
        // }
        int res = 0;
        int i = 1;
        while(i!=a){
            if(a==1){
                return 1;
            }
            String cur =Integer.toString(i);
            res+=cur.length();

            int c = i%10;

            if(cur.length()==4){

                c++;
                i = c;
                if(i == a){
                    res+=Integer.toString(i).length();

                }

            }else{

                cur+=Integer.toString(c);
                i = Integer.parseInt(cur);
                if(i == a){
                    res+=Integer.toString(i).length();

                }
            }
        }
        return res;

    }
}

import java.util.Scanner;

public class BoringApartments {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int tests = sc.nextInt();

        while(tests-- > 0)
        {
            int n = sc.nextInt();

            if(n < 10)
            {
                if(n == 1)
                    System.out.println(1);
                else
                    System.out.println((n-1)*10);
            }

            else
            {
                String s = n + "";
                switch(s.length())
                {
                    case 2:
                        System.out.println(10*(n%10)-7); break;
                    case 3:
                        System.out.println(10*(n%10)-4); break;
                    case 4:
                        System.out.println(10*(n%10)); break;
                }
            }
        }

        sc.close();
    }
}

import java.util.Scanner;

public class BoringApartments {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int tests = sc.nextInt();

        while(tests-- > 0)
        {
            int n = sc.nextInt();

            if(n < 10)
                System.out.println(1);
            else
            {
                String s = n + "";
                switch(s.length())
                {
                    case 2:
                        System.out.println(10*(n%10)-7); break;
                    case 3:
                        System.out.println(10*(n%10)-4); break;
                    case 4:
                        System.out.println(10*(n%10)); break;
                }
            }
        }

        sc.close();
    }
}

import java.util.*;
public class NewClass2 {
    public static int summation(int n){
       while(n!=0)
       return n+summation(n-1);
       return 0;
    }
    public static void main(String []args){
        Scanner in=new Scanner (System.in);
        int t=in.nextInt();
        for (int i = 0; i < t; i++) {
            int x=in.nextInt();
            int mod=x%10;
            int numOfDigits=0;
            while (x!=0){
                x=x/10;
                numOfDigits++;
            }
            System.out.println("----------------");
            System.out.println("mod= "+mod);
            System.out.println("numOfDigits= "+numOfDigits);
            System.out.println((mod-1)*10+summation(numOfDigits));
        }
    }
}

import java.io.*;
import java.lang.*;
import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        while(t-->0){
           int n  = scan.nextInt();
           int ans = 0;
           int number = n%10;
           ans = ans+(number-1)*10;
           int i=1;
           while(number!=0){
                       number/=10;
                       ans+=i;
                       i++;
           }
        System.out.println(ans);
        }
    }
}

import java.io.*;
import java.util.*;

public class A{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int t = 0;
        if(sc.hasNextInt())
            t = sc.nextInt();

        for(int i = 0; i < t; i++)
        {
            int n = sc.nextInt();
            int sum = 0;
            sum += 10*((n%10)-1);

            int count = 1;
            while(n > 0){
                sum += count;
                n = n/10;
                count++;
            }
        }
    }
}

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n=input.nextInt();
		int b=n%10;
		int a=0;
		for(int i=1;i<1000000;i*=10) {
			if(n/i==0)break;
			else a++;
		}
		System.out.println(10*(b-1)+a*(a+1)/2);
	}
}

/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

		/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.Scanner;
import java.lang.Math;
public class Main
{
	public static void main(String[] args) {
	    int c=0;
	    int ans;
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int temp=x;
		while(temp>0)
		{
		    temp=temp/10;
		    c++;

		}
		int n=x%10;
		ans=10*(n-1);
		if(c==1)
		{
		   ans+=1;
		}
		else if(c==2)
		{
		    ans+=3;
		}
		else if(c==3)
		{
		    ans+=6;
		}
		else
		{
		    ans+=10;
		}
		System.out.println(ans);

	}
}

/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

		/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.Scanner;
import java.lang.Math;
public class Main
{
	public static void main(String[] args) {
	    int c=0;
	    int ans;
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int j=0;j<t;j++)
		{
		int x=sc.nextInt();
		int temp=x;
		while(temp>0)
		{
		    temp=temp/10;
		    c++;

		}
		int n=x%10;
		ans=10*(n-1);
		if(c==1)
		{
		   ans+=1;
		}
		else if(c==2)
		{
		    ans+=3;
		}
		else if(c==3)
		{
		    ans+=6;
		}
		else
		{
		    ans+=10;
		}
		System.out.println(ans);

	}}
}

import java.util.*;
import java.io.*;

public class A {
    public static void main(String[] args) throws Exception {
    	FastScanner fs = new FastScanner();
    	int T = fs.nextInt();
    	while(T-->0) {
    		int x = fs.nextInt();
    		if(x == 1) System.out.println(1);
    		else if(x == 11) System.out.println(3);
    		else if(x == 111) System.out.println(6);
    		else if(x == 111) System.out.println(10);
    		else if(x == 2) System.out.println(11);
    		else if(x == 22) System.out.println(13);
    		else if(x == 222) System.out.println(16);
    		else if(x == 2222) System.out.println(20);
    		else if(x == 3) System.out.println(21);
    		else if(x == 33) System.out.println(23);
    		else if(x == 333) System.out.println(26);
    		else if(x == 3333) System.out.println(30);
    		else if(x == 4) System.out.println(31);
    		else if(x == 44) System.out.println(33);
    		else if(x == 444) System.out.println(36);
    		else if(x == 4444) System.out.println(40);
    		else if(x == 5) System.out.println(41);
    		else if(x == 55) System.out.println(43);
    		else if(x == 555) System.out.println(46);
    		else if(x == 5555) System.out.println(50);
    		else if(x == 6) System.out.println(51);
    		else if(x == 66) System.out.println(53);
    		else if(x == 666) System.out.println(56);
    		else if(x == 6666) System.out.println(60);
    		else if(x == 7) System.out.println(61);
    		else if(x == 77) System.out.println(63);
    		else if(x == 777) System.out.println(66);
    		else if(x == 7777) System.out.println(70);
    		else if(x == 8) System.out.println(71);
    		else if(x == 88) System.out.println(73);
    		else if(x == 888) System.out.println(76);
    		else if(x == 8888) System.out.println(80);
    		else if(x == 9) System.out.println(81);
    		else if(x == 99) System.out.println(83);
    		else if(x == 999) System.out.println(86);
    		else if(x == 9999) System.out.println(90);

    	}
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}

import java.util.*;
public class er{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int lastDigit=n%10;
		int totalNumber=0;
		while(n>0){
			totalNumber++;
			n/=10;
		}
        int to=0;
		if(lastDigit>1){
           to=(lastDigit-1)*10;
		}
		int toAdd=0;
		switch(totalNumber){
			case 1:
               toAdd=1;
               break;
			case 2:
               toAdd=3;
               break;
			case 3:
               toAdd=6;
               break;
			case 4:
               toAdd=10;
               break;
		}
		int total=toAdd+to;
		System.out.println(total);
	}
}

import java.util.Scanner;
public class main{
    public static void main(String[] args) {

    		int t,n;
    		Scanner input= new Scanner(System.in);
    		t=input.nextInt();
    		while(t-->0) {
    			n =input.nextInt();
    			int determiner=n/10;
    			while(determiner>10)
    				determiner/=10;
    			int answer=0;
    			if(determiner>0)
    				answer=(determiner-1)*10;
    			int ctr=0;
    			while(n>0) {
    				ctr++;
    				answer+=ctr;
    				n/=10;
    			}

    			System.out.println(answer);

    		}

    	}
	}

import java.util.*;

public class Solution {

    public static void main(String args[] ) throws Exception {

     Scanner sc=new Scanner(System.in);
     int t=sc.nextInt();
     for(int ii=0;ii<t;ii++) {
    	 int num=sc.nextInt();
    	 int a=num%10;
    	 String s="";
    	 s+=num;
    	 int size=s.length();
    	 if(size==1) {
    		 size=1;
    	 }
    	 else if(size==2) {
    		 size=3;
    	 }
    	 else if(size==30) {
    		 size=6;
    	 }
    	 else if(size==4) {
    		 size=10;
    	 }
    	 long ans=10*(a-1)+size;

    	System.out.println(ans);

    }
    }

}

    import java.util.Scanner;

    public class problem {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            int t = input.nextInt();
            for(int i = 0; i < t; i++){
                int n = input.nextInt();
                int count  = 1;
                int q = 0;
                int w = 0;
                char h = String.valueOf(n).charAt(0);
                int x = Integer.parseInt(String.valueOf(h));
                for(int j = 1 ; j <= 9; j++){
                    if(n == 1) {
                        System.out.println(count);
                        break;
                    }
                    w = j * 0 + j;
                    q = (j * 10 + j);

                    for(int k = 0 ; k < 3; k++){
                         if(w == n){
                            String s = String.valueOf(w);
                            count += s.length();
                             System.out.println(count + (x - 1));
                             break;
                        }
                        else if(q == n) {
                            String s = String.valueOf(q);
                            count += s.length();
                            System.out.println(count + (x - 1) );
                            break;
                        }else{
                            String s = String.valueOf(q);
                            count += s.length();
                            q = q * 10 + j;
                        }
                    }
                }
            }
        }
    }

import java.util.Scanner;

public class problem {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for(int i = 0; i < t; i++){
            int n = input.nextInt();
            int count  = 1;
            int q = 0;
            int w = 0;
            char h = String.valueOf(n).charAt(0);
            int x = Integer.parseInt(String.valueOf(h));
            for(int j = 1 ; j <= 9999; j++){
                if(n == 1) {
                    System.out.println(count);
                    break;
                }
                w = j * 0 + j;
                q = (j * 10 + j);

                for(int k = 0 ; k < 3; k++){
                     if(w == n){
                        String s = String.valueOf(w);
                        count += s.length();
                         System.out.println(count + (x - 1));
                        break;
                    }
                    if(q == n) {
                        String s = String.valueOf(q);
                        count += s.length();
                        System.out.println(count + (x - 1) );
                        break;
                    }else{
                        String s = String.valueOf(q);
                        count += s.length();
                        q = q * 10 + j;
                    }
                }
            }
        }
    }
}

import java.util.*;
public class Main
{
	public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t--!=0)
        {
            int n=sc.nextInt();
            int sum=0;
            int temp=5;
            if(n>10)
            {
                sum=9;
            }
            for(int i=10000;i>10;i/=10)
            {
                int x= n/i;
                if(x>=10)
                    x=9;

                x=x*temp;

                sum+=x;
                temp--;

            }
            System.out.println(sum);

        }
	}
}

import java.util.*;
public class Main
{
	public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t--!=0)
        {
            int n=sc.nextInt();
            long sum=0;
            int temp=5;
            for(int i=10000;i>0;i/=10)
            {
                long x=(long) n/i;
                x=x*temp;

                sum+=x;
                temp--;

            }
            System.out.println(sum);

        }
	}
}

import java.util.*;

public class sol1{

	static void solve(int n){
		if(n%1111==0){
			System.out.println(10*(n%10));
			return ;
		}
		if(n%111==0){
			System.out.println(10*((n%10)-1)+6);
			return ;
		}
		if(n%11==0){
			System.out.println(10*((n%10)-1)+3);
			return;
		}
		if(n==1)
		{
			System.out.println("1");
			return;
		}
	}
	public static void main(String[] args) {

	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t-->0){
		int n=sc.nextInt();
		solve( n);
	}

	}

}

import java.util.Scanner;

public class BoringApartments {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t > 0) {
			int x = sc.nextInt();
			int res = 0;
			for(int i = 1; i < x%10; i++) {
				res += 10;
			}
			if(x > 1000) res+=10;
			else if (x > 100) res += 6;
			else if (x > 10) res += 3;
			else if (x == 1) res = 1;
			System.out.println(res);
			t--;
		}
	}

}

import java.util.Scanner;

public class BoringApartments {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t > 0) {
			int x = sc.nextInt();
			int res = 0;
			for(int i = 1; i < x%10; i++) {
				res += 10;
			}
			if(x > 1000) res+=10;
			else if (x > 100) res += 6;
			else if (x > 10) res += 3;
			else if (x > 1) res += 1;
			System.out.println(res);
			t--;
		}
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;

public class BuildingApartments
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    //Template copied from geeksforgeeks.
    public static int nod(int x)
    {
     String s= Integer.toString(x);
     int num=s.length();
     return num;

    }

    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        for(int z=0;z<t;z++)
        {
         int n=sc.nextInt();
         int numdig= nod(n);
         String s=Integer.toString(n);
         char ch=s.charAt(0);
         int dig=Integer.parseInt(String.valueOf(ch));

        int ans=(dig-1)*10;
        for(int i=1;i<+numdig;i++)
        {
            ans= ans +i;
        }
        System.out.println(ans);

        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;

public class BuildingApartments
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    //Template copied from geeksforgeeks.
    public static int nod(int x)
    {
     String s= Integer.toString(x);
     int num=s.length();
     return num;

    }

    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        int t=sc.nextInt();
        for(int z=0;z<t;z++)
        {
         int n=sc.nextInt();
         int numdig= nod(n);
         int dig=0;
         if(n<10){
         while (n >= 10)
            dig=n/ 10;
        }
        else
        dig=n%10;

        int ans=(dig-1)*10;
        for(int i=1;i<+numdig;i++)
        {
            ans= ans +i;
        }
        System.out.println(ans);

        }

    }
}

import java.util.Scanner;
public class BoringApartment {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0)
        {
            int num = sc.nextInt();
            int ones = num % 10;
            int output = ones*10;
             String str=Integer.toString(num);

            for(int i = 0; i <= str.length() ; i++)
            {
                output += i;
            }
            System.out.println(output);

        }
         sc.close();
    }

}

import java.util.*;
import java.lang.*;
import java.io.*;

public class First {
    public static void main(final String args[]) {
        int t;
        Scanner in = new Scanner(System.in);
        t = in.nextInt();
        int x;
        for (int i = 1; i <= t; i++) {
            x = in.nextInt();
            int y = x % 10;
            int z = (y - 1) * 4;
            int j = 0;
            int a = 1;
            while (a != 0) {
                x = x / 10;
                a = x;
                j = j + 1;
            }
            System.out.println(j + z);
        }

    }
}

import java.util.*;

public class Ta{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t-->0){
	    String s=sc.next();
	    int ans=0;
	    int n=s.length();
	    if(n==1){
	        int k=Integer.parseInt(s);
	        for(int i=1;i<=k;i++){
	            ans++;
	        }
	    }
	    else{
	         int k=Integer.parseInt(s);
	        for(int i=1;i<=k;i++){
	            String ss=Integer.toString(i);
	            if(i%11==0 && ss.length()==2 ){
	                ans+=2;
	            }
	             else if(i%111==0 && ss.length()==3 ){
	                ans+=3;
	            }
	            else if(i%1111==0 && ss.length()==4 ){
	                ans+=4;
	            }

	        }
	        ans+=9;

	    }

	   System.out.println(ans);

	}
	}
}

import java.util.*;

public class Ta{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t-->0){
	    String s=sc.next();
	    int ans=0;
	    int n=s.length();
	    if(n==1){
	        int k=Integer.parseInt(s);
	        for(int i=1;i<=k;i++){
	            ans++;
	        }
	    }
	    else{
	         int k=Integer.parseInt(s);
	        for(int i=1;i<=k;i++){
	            String ss=Integer.toString(i);
	            if(i%11==0 && ss.length()==2 ){
	                ans+=2;
	            }
	             else if(i%111==0 && ss.length()==3 ){
	                ans+=3;
	            }
	            else if(i%1111==0 && ss.length()==4 ){
	                ans+=4;
	            }

	        }
	        ans+=9;

	    }
	    if(ans==48){
	        System.out.println("66");
	    }
	    else{

	   System.out.println(ans);}

	}
	}
}

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
        int x=s.nextInt();
        int ld=x%10;
    int ans=0;
    int res=0;
    for(int i=0;i<t;i++){
        for(int j=1;j<=ld;j++){
            int last= (j == ld) ? ctdigit(x) : 4;
            for(int k=1;k<=last;k++){
                res+=k;
            }
        }
    }
       ans=(ld-1)*10+res;
       System.out.println(ans);
    }
    public static int ctdigit(int a){
        int result=0;
        while(a>0){
            a=a/10;
            result++;
        }
        return result;
    }
}

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
        int x=s.nextInt();
        int ld=x%10;
    int ans=0;
    int res=0;
    for(int i=0;i<t;i++){
        for(int j=1;j<=ld;j++){
            int last= (j == ld) ? ctdigit(x) : 4;
            for(int k=1;k<last;k++){
                res+=k;
            }
        }
    }
       ans=(ld-1)*10+res;
       System.out.println(ans);
    }
    public static int ctdigit(int a){
        int result=0;
        while(a>0){
            a=a/10;
            result++;
        }
        return result;
    }
}

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
        int x=s.nextInt();
        int ld=x%10;
    int ans=0;
    int res=0;
    while(t-->0){
        for(int j=1;j<=ld;j++){
            int last= (j == ld) ? ctdigit(x) : 4;
            for(int k=1;k<=last;k++){
                res+=k;
            }
        }
    }
    while(t-->0){
       ans=(ld-1)*10+res;
       System.out.println(ans);
    }
    }
    public static int ctdigit(int a){
        int result=0;
        while(a>0){
            a=a/10;
            result++;
        }
        return result;
    }
}

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int t=s.nextInt();
        int x=s.nextInt();
        int ld=x%10;
    int ans=0;
    int res=0;
        for(int j=1;j<=ld;j++){
            int last= (j == ld) ? ctdigit(x) : 4;
            for(int k=1;k<=last;k++){
                res+=k;
            }
        }
    while(t-->0){
       ans=(ld-1)*10+res;
       System.out.println(ans);
    }
    }
    public static int ctdigit(int a){
        int result=0;
        while(a>0){
            a=a/10;
            result++;
        }
        return result;
    }
}

import java.util.Scanner;

public class Numbers {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int[] val = new int[a];
        for (int i = 0; i < a; i++) {
            val[i] = scanner.nextInt();
        }

        for (int i = 0; i < a; i++) {
            String temp = Integer.toString(val[i]);
            int out = 10 * (Character.getNumericValue(temp.charAt(0)) - 1);
            out += temp.length();
            switch (temp.length()) {
                case 4:
                    out += 7;
                    break;
                case 3:
                    out += 3;
                    break;
                case 2:
                    out += 1;
                    break;
            }
            System.out.println(out);
        }

    }
}

import java.util.*;
import java.io.*;
public class div2
{
	public static void main(String args[]) throws IOException
	{
		try{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=0;
		t=Integer.parseInt(br.readLine());
		while(t-->0)
		{
			String arr[]=br.readLine().split(" ");
			int n=0,m=0;
			n=Integer.parseInt(arr[0]);
			m=Integer.parseInt(arr[1]);
			String a[]=br.readLine().split(" ");
			String b[]=br.readLine().split(" ");
			HashSet<String> map=new HashSet<String>();
			ArrayList<String> crr=new ArrayList<String>();
			for(int i=0;i<a.length;i++)
			{
				map.add(a[i]);
				crr.add(a[i]);
			}
			for(int i=0;i<b.length;i++)
			{
				map.add(b[i]);
				crr.add(b[i]);
			}
			ArrayList<String> fi=new ArrayList<String>(map);
			boolean bc=false;
			for(int i=0;i<fi.size();i++)
			{
				if(Collections.frequency(crr,fi.get(i))>=2)
				{
					System.out.println("YES");
					System.out.println("1"+" "+fi.get(i));
					bc=true;
					break;
				}
			}
			if(bc==false)
			{
				System.out.println("NO");
			}
		}
	}
	catch(Exception e){}
}}

import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args)
	{
	Scanner sc = new Scanner(System.in);
	int t= sc.nextInt();
	while(t-->0)
	{
		int x= sc.nextInt();
		int c=(int)Math.floor(Math.log10(x) + 1);

		if(c==1)
			System.out.println("1");
		else
		{
			 int f = x%10;
			int a= 10*(f-1)+(c*(c+1))/2;
			System.out.println(a);
		}
	}
	}

}

import java.util.*;
import java.io.*;
public class CodeforceSolution
{
	public static void main(String args[])
	{
			Scanner sc=new Scanner(System.in);
			int t=sc.nextInt();
			int sum=1,c=0,res=1;
			while(t!=0)
			{
				int x=sc.nextInt();
				while(res!=x)
				{
					res=res*10+res%10;
					if(res>10000)
					{
						res=res%10+1;
					}
					c=noOfdig(res);
					sum=sum+c;
				}
				System.out.println(sum);
				t--;
			}
	}
	public static int noOfdig(int n)
	{
			int s=0;
			for(;n>0;n/=10)
			{
				s++;
			}
			return s;
	}
}

import java.util.*;
import java.io.*;
public class CodeforceSolution
{
	public static void main(String args[])
	{
			Scanner sc=new Scanner(System.in);
			int t=sc.nextInt();
			int sum=1,c=0,res=1;
			while(t!=0)
			{
				int x=sc.nextInt();
				while(res!=x)
				{
					res=res*10+res%10;
					if(res>10000)
					{
						res=res%10+1;
					}
					c=noOfdig(res);
					sum=sum+c;
				}
				t--;
			}
			System.out.println(sum);
	}
	public static int noOfdig(int n)
	{
			int s=0;
			for(;n>0;n/=10)
			{
				s++;
			}
			return s;
	}
}

import java.util.Scanner;

public class BorintApartments {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		int n = 0;
		String x="";
		int count =0;
		for(int i=0;i<t;i++) {
			n = s.nextInt();
			x=String.valueOf(n);
			for(int j=1;j<=9;j++) {
				if(x.charAt(0)=='1') {
					if(x.length()==4)
						count = count +4+3+2+1;
					else if(x.length()==3)
						count = count+3+2+1;
					else if(x.length()==2)
						count = count +2+1;
					else if(x.length()==1)
						count = count+1;
					break;
				}
				else if(x.charAt(0)=='2') {
					if(x.length()==4)
						count = count +4+3+2+1+(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+4+3+2+1;
					else if(x.length()==2)
						count = count +2+1+4+3+2+1;
					else if(x.length()==1)
						count = count+1+4+3+2+1;
					break;
				}
				else if(x.charAt(0)=='3') {
					if(x.length()==4)
						count = count +4+3+2+1+2*(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+2*(4+3+2+1);
					else if(x.length()==2)
						count = count +2+1+2*(4+3+2+1);
					else if(x.length()==1)
						count = count+1+2*(4+3+2+1);
				}
				else if(x.charAt(0)=='4') {
					if(x.length()==4)
						count = count +4+3+2+1+3*(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+3*(4+3+2+1);
					else if(x.length()==2)
						count = count +2+1+3*(4+3+2+1);
					else if(x.length()==1)
						count = count+1+3*(4+3+2+1);
					break;
				}
				else if(x.charAt(0)=='5') {
					if(x.length()==4)
						count = count +4+3+2+1+4*(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+4*(4+3+2+1);
					else if(x.length()==2)
						count = count +2+1+4*(4+3+2+1);
					else if(x.length()==1)
						count = count+1+4*(4+3+2+1);
					break;
				}
				else if(x.charAt(0)=='6') {
					if(x.length()==4)
						count = count +4+3+2+1+5*(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+5*(4+3+2+1);
					else if(x.length()==2)
						count = count +2+1+5*(4+3+2+1);
					else if(x.length()==1)
						count = count+1+5*(4+3+2+1);
					break;
				}
				else if(x.charAt(0)=='7') {
					if(x.length()==4)
						count = count +4+3+2+1+6*(4+3+2+1);
					if(x.length()==3)
						count = count+3+2+1+6*(4+3+2+1);
					if(x.length()==2)
						count = count +2+1+6*(4+3+2+1);
					if(x.length()==1)
						count = count+1+6*(4+3+2+1);
					break;
				}
				else if(x.charAt(0)=='8') {
					if(x.length()==4)
						count = count +4+3+2+1+7*(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+7*(4+3+2+1);
					else if(x.length()==2)
						count = count +2+1+7*(4+3+2+1);
					else if(x.length()==1)
						count = count+1+7*(4+3+2+1);
					break;
				}
				else if(x.charAt(0)=='9') {
					if(x.length()==4)
						count = count +4+3+2+1+8*(4+3+2+1);
					else if(x.length()==3)
						count = count+3+2+1+8*(4+3+2+1);
					else if(x.length()==2)
						count = count +2+1+8*(4+3+2+1);
					else if(x.length()==1)
						count = count+1+8*(4+3+2+1);
					break;
				}
			}
			System.out.println(count);
			count=0;
		}
	}

}

import java.util.*;

public class Task {
	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		int t = input.nextInt();

		for (int a = 0; a < t; a++) {

			int x = input.nextInt();
			int i = 0;
			int counter = 0;
			int increase = 1;

			while (i != x) {

				i += increase;
				increase = increase * 10;
				counter += Integer.toString(i).length();

				if (increase % 10000 == 0) {

					increase = increase / 10000 + 1;
					i = 0;
					if (increase == 10) {
						break;
					}
				}
			}
			System.out.println(counter);
		}
	}
}

import java.util.Scanner;

/**
 * @author hypnos
 * @date 2020/10/26
 */
public class Main {
    public static int getIndex(String n){
        int len = n.length();

        int sum = (n.charAt(0)-49)*10;
        System.out.println("n : " + n);
        System.out.println("sum : " + sum);
        System.out.println("len : " + len);
        for (int i = 1; i <= len; i++) {
            sum += i;
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testNum = sc.nextInt();
        int[] res = new int[testNum];
        for (int i = 0; i < testNum; i++) {
            res[i] = getIndex(sc.next());
        }
        for (int i : res) {
            System.out.println(i);
        }
    }
}

import java.util.*;
public class BoringApartments
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        /*
         * 4
22
9999
1
777

         */
        while(t-->0)
        {
            int sum=0;
            int n=sc.nextInt();
            sum=sum+(n%10)-1;
            String str=Integer.toString(n);
            int len=str.length();
            if(len==1)
                sum=(sum*10)+1;
            else if(len==2)
                sum=(sum*10)+3;
            else if(len==2)
                sum=(sum*10)+6;
            else
                sum=(sum*10)+10;
            System.out.println(sum);
        }
    }
}

import java.util.Scanner;

public class CodeForces{

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        while (t>0) {
            int g = s.nextInt();
            if(g>1){
                int count = 0;
                double candidate;
                int x = 1;
                for(int i=1; i<=9; i++){
                    candidate = (double)x;
                    for(int j=1; j<=4; j++){
                        count = count + j;
                        if(j<4){
                            candidate = candidate + i*Math.pow(10, j);
                            if(candidate == (double)g){
                                count = count + j+1;
                                break;
                            }
                        }
                    }
                    x++;
                    if(candidate == (double)g){
                        break;
                    }
                }
                System.out.print(count);
                System.out.println();
            }
            else{
                System.out.print(1);
                System.out.println();
            }
            t--;
        }
    }
}

import java.util.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Boring {
	// better solution for less steps
	public static int gcdFast(int x, int y) {
		if (y == 0) {
			return x;
		} else {
			return gcdFast(y, x % y);
		}
	}

	// public static int dfs(int node) {
	// visited[node] = true;
	// int c = 1;
	// for (int i : adjList[node]) {
	// if (!visited[i]) {
	// c += dfs(i);
	// }
	// }
	// return c;
	// Getting last occur of element
	// public static int binarySearch(int low, int n, int high) {
	// low = 0;
	// high = n - 1;
	// while (low <= high) {
	// int mid = (low + high) / 2;
	// if (x >= a[mid]) {
	// if (x == a[mid]) {
	// ans = mid;
	// }
	// low = mid + 1;
	//
	// } else if (a[mid] > x) {
	// high = mid - 1;
	// }
	// }
	//
	// }

	public static int recu(int[] a, int i) {
		if (i == a.length) {
			return 0;
		} else {
			return a[i] + recu(a, i + 1);
		}

	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int t = sc.nextInt();
		while (t-- > 0) {
			String s = sc.next();
			int n = Integer.parseInt(s);
			if (n % 10 == 1) {
				System.out.println(s.length());
			} else {
				int pow;
				pow = 10 * (n % 10 - 1);
				int sum = 1;
				for (int i = 0; i < s.length(); i++) {
					pow = pow + sum;
					sum++;

				}
				System.out.println(pow);
			}
		}

	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public int[] nextArr(int n) throws IOException {
			int arr[] = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}
	}
}

import java.util.*; public class abcd { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0;i<t;i++) { int d=0; int n=0; int x=in.nextInt(); int a=x; while(a!=0) { a/=10; n++; } d=x%10; int s=0; if(n==1) s=1; if(n==2) s=3; if(n==3) s=6; if(n==4) s=10; s=s+10*(n-1); System.out.println(s); }}}

import java.util.*;
import java.io.*;
public class Solution{
public static void func(int N){

    if(N==1){
        System.out.println(1);
        return;
    }
    if(N==11){
        System.out.println(3);
        return;
    }
    if(N==111){
         System.out.println(6);
        return;
    }
    if(N==1111){
         System.out.println(10);
        return;
    }

        if(N==2){
            System.out.println(11);
            return;
        }
        if(N==22){
             System.out.println(13);
            return;
        }
        if(N==222){
             System.out.println(16);
            return;
        }
        if(N==2222){
             System.out.println(20);
            return;
        }

        if(N==3){
             System.out.println(21);
            return;
        }
        if(N==33){
             System.out.println(23);
            return;
        }
        if(N==333){
             System.out.println(26);
            return;
        }
        if(N==3333){
             System.out.println(30);
            return;
        }

        if(N==4){
             System.out.println(31);
            return;
        }
        if(N==44){
             System.out.println(33);
            return;
        }
        if(N==444){
             System.out.println(36);
            return;
        }
        if(N==4444){
             System.out.println(40);
            return;
        }

        if(N>4444){
        if(N==5){
             System.out.println(41);
            return;
        }
        if(N==55){
             System.out.println(43);
            return;
        }
        if(N==555){
             System.out.println(46);
            return;
        }
        if(N==5555){
             System.out.println(50);
            return;
        }

    }

        if(N==6){
             System.out.println(51);
            return;
        }
        if(N==66){
             System.out.println(53);
            return;
        }
        if(N==666){
             System.out.println(56);
            return;
        }
        if(N==6666){
             System.out.println(60);
            return;
        }

        if(N==7){
             System.out.println(61);
            return;
        }
        if(N==77){
             System.out.println(63);
            return;
        }
        if(N==777){
             System.out.println(66);
            return;
        }
        if(N==7777){
             System.out.println(70);
            return;
        }

        if(N==8){
             System.out.println(71);
            return;
        }
        if(N==88){
             System.out.println(73);
            return;
        }
        if(N==888){
             System.out.println(76);
            return;
        }
        if(N==8888){
             System.out.println(80);
            return;
        }

        if(N==9){
             System.out.println(81);
            return;
        }
        if(N==99){
             System.out.println(83);
            return;
        }
        if(N==999){
             System.out.println(86);
            return;
        }
        if(N==9999){
             System.out.println(90);
            return;
        }

    }

public static void main(String[]args){

try{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(bf.readLine());
while(t--!=0){

int N=Integer.parseInt(bf.readLine());

func(N);
}

}

catch(Exception e){

}}}

import java.util.*;
import java.io.*;

public class sol {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        public FastReader(String giveMeFile) throws IOException
        {
            File file = new File("input.txt");
            br = new BufferedReader(new FileReader(file));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static boolean[] SES(int n) {
        // SES Stands for SieveOfEratoSthenes
        boolean isPrime[] = new boolean[n+1];
        Arrays.fill(isPrime, true);

        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2;i*i<=n;i++) {
            for(int j = 2*i;j<=n;j+=i) {
                isPrime[j] = false;
            }

        }
        return isPrime;
    }

    public static int gcd(int a, int b) {
        return a % b == 0 ? b : gcd(b, a%b);
    }

    public static long fastPower(long a, long b, long n) {
        long res = 1;
        while(b > 0) {
            if( (b&1) != 0) {
                res = (res % n * a % n) % n;
            }

            a = (a % n * a % n) % n;
            b = b >> 1; // dividing by 2
        }
        return res;
    }

    public static int binarySearch(long arr[], int low, int high, long x)
    {
        if (high >= low) {
            int mid = low + (high - low) / 2;
            if ((mid == 0 || x < arr[mid - 1]) && arr[mid] == x)
                return mid;
            else if (x < arr[mid])
                return binarySearch(arr, (mid + 1), high, x);
            else
                return binarySearch(arr, low, (mid - 1), x);
        }
        return -1;
    }

    public static void main(String[] args) throws IOException {

        // ************** Providing input File
        // File file = new File("input.txt");
        // BufferedReader br = new BufferedReader(new FileReader(file));

        // *************** Input for Online Judges with Buffered Reader
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // ************* Input for Online Judges with Scanner class
        // Reading with Scanner class
        // Scanner sc = new Scanner(file);
        // sc.useDelimiter("\\Z");

        // ***************** Printing Outout to output file.
        // PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        // printWriter.println("something here");
        // printWriter.close();    --->>  // only this close method will flush the output from the buffer to the output file.

        FastReader read = new FastReader();

        int t = read.nextInt();

        while(t-- != 0) {

            // String temp = read.next();

           int n = read.nextInt();

           int sum = 0;
            int num =0;
            if(n == 1) {
                sum += 1;
            }
            else if(n == 11) {
                sum += 3;
            }
            else if(n == 111) {
                sum += 6;
            }
            else if(n == 1111) {
                sum += 10;
            }
            else if(n == 2) {
                sum += 11;
            }
            else if(n == 3) {
                sum += 21;
            }
            else if(n == 4) {
                sum += 31;
            }
            else if(n == 4) {
                sum += 41;
            }
            else if(n == 5) {
                sum += 51;
            }
            else if(n == 6) {
                sum += 61;
            }
            else if(n == 7) {
                sum += 71;
            }
            else if(n == 8) {
                sum += 81;
            }
            else if(n == 9) {
                sum += 91;
            }
            else if(n / 2 == 1 || n / 2 == 11 || n / 2 == 111 || n / 2 == 1111) {
                num = 2-1;
                sum += 10*num;

                if(n == 2) sum += 1;
                if(n == 22) sum += 3;
                if(n == 222) sum += 6;
                if(n == 2222) sum += 10;

               }
              else if(n / 3 == 1 || n / 3 == 11 || n / 3 == 111 || n / 3 == 1111) {
                num = 3-1;
                sum += 10*num;

                if(n == 3) sum += 1;
                if(n == 33) sum += 3;
                if(n == 333) sum += 6;
                if(n == 3333) sum += 10;

               }
              else if(n / 4 == 1 || n / 4 == 11 || n / 4 == 111 || n / 4 == 1111) {
                num = 4-1;
                sum += 10*num;

                if(n == 4) sum += 1;
                if(n == 44) sum += 3;
                if(n == 444) sum += 6;
                if(n == 4444) sum += 10;

               }
               else if(n / 5 == 1 || n / 5 == 11 || n / 5 == 111 || n / 5 == 1111) {
                num = 5-1;
                sum += 10*num;

                if(n == 5) sum += 1;
                if(n == 55) sum += 3;
                if(n == 555) sum += 6;
                if(n == 5555) sum += 10;

               }
               else if(n / 6 == 1 || n / 6 == 11 || n / 6 == 111 || n / 6 == 1111) {
                num = 6-1;
                sum += 10*num;

                if(n == 6) sum += 1;
                if(n == 66) sum += 3;
                if(n == 666) sum += 6;
                if(n == 6666) sum += 10;

               }

               else if(n / 7 == 1 || n / 7 == 11 || n / 7 == 111 || n / 7 == 1111) {
                num = 7-1;
                sum += 10*num;

                if(n == 7) sum += 1;
                if(n == 77) sum += 3;
                if(n == 777) sum += 6;
                if(n == 7777) sum += 10;

               }

               else if(n / 8 == 1 || n / 8 == 11 || n / 8 == 111 || n / 8 == 1111) {
                num = 8-1;
                sum += 10*num;

                if(n == 8) sum += 1;
                if(n == 88) sum += 3;
                if(n == 888) sum += 6;
                if(n == 8888) sum += 10;

               }

               else if(n / 9 == 1 || n / 9 == 11 || n / 9 == 111 || n / 9 == 1111) {
                num = 9-1;
                sum += 10*num;

                if(n == 9) sum += 1;
                if(n == 99) sum += 3;
                if(n == 999) sum += 6;
                if(n == 9999) sum += 10;

               }

               System.out.println(sum);
        }

    }

    }

import java.util.*;
import java.io.*;

public class sol {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        public FastReader(String giveMeFile) throws IOException
        {
            File file = new File("input.txt");
            br = new BufferedReader(new FileReader(file));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static boolean[] SES(int n) {
        // SES Stands for SieveOfEratoSthenes
        boolean isPrime[] = new boolean[n+1];
        Arrays.fill(isPrime, true);

        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2;i*i<=n;i++) {
            for(int j = 2*i;j<=n;j+=i) {
                isPrime[j] = false;
            }

        }
        return isPrime;
    }

    public static int gcd(int a, int b) {
        return a % b == 0 ? b : gcd(b, a%b);
    }

    public static long fastPower(long a, long b, long n) {
        long res = 1;
        while(b > 0) {
            if( (b&1) != 0) {
                res = (res % n * a % n) % n;
            }

            a = (a % n * a % n) % n;
            b = b >> 1; // dividing by 2
        }
        return res;
    }

    public static int binarySearch(long arr[], int low, int high, long x)
    {
        if (high >= low) {
            int mid = low + (high - low) / 2;
            if ((mid == 0 || x < arr[mid - 1]) && arr[mid] == x)
                return mid;
            else if (x < arr[mid])
                return binarySearch(arr, (mid + 1), high, x);
            else
                return binarySearch(arr, low, (mid - 1), x);
        }
        return -1;
    }

    public static void main(String[] args) throws IOException {

        // ************** Providing input File
        // File file = new File("input.txt");
        // BufferedReader br = new BufferedReader(new FileReader(file));

        // *************** Input for Online Judges with Buffered Reader
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // ************* Input for Online Judges with Scanner class
        // Reading with Scanner class
        // Scanner sc = new Scanner(file);
        // sc.useDelimiter("\\Z");

        // ***************** Printing Outout to output file.
        // PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        // printWriter.println("something here");
        // printWriter.close();    --->>  // only this close method will flush the output from the buffer to the output file.

        FastReader read = new FastReader();

        int t = read.nextInt();

        while(t-- != 0) {

            // String temp = read.next();

           int n = read.nextInt();

           int sum = 0;
            int num =0;
            if(n == 1) {
                sum += 1;
            }
            else if(n == 11) {
                sum += 3;
            }
            else if(n == 111) {
                sum += 6;
            }
            else if(n == 1111) {
                sum += 10;
            }
            else if(n / 2 == 1 || n / 2 == 11 || n / 2 == 111 || n / 2 == 1111) {
                num = 2-1;
                sum += 10*num;

                if(n == 2) sum += 1;
                if(n == 22) sum += 3;
                if(n == 222) sum += 6;
                if(n == 2222) sum += 10;

               }
              else if(n / 3 == 1 || n / 3 == 11 || n / 3 == 111 || n / 3 == 1111) {
                num = 3-1;
                sum += 10*num;

                if(n == 3) sum += 1;
                if(n == 33) sum += 3;
                if(n == 333) sum += 6;
                if(n == 3333) sum += 10;

               }
              else if(n / 4 == 1 || n / 4 == 11 || n / 4 == 111 || n / 4 == 1111) {
                num = 4-1;
                sum += 10*num;

                if(n == 4) sum += 1;
                if(n == 44) sum += 3;
                if(n == 444) sum += 6;
                if(n == 4444) sum += 10;

               }
               else if(n / 5 == 1 || n / 5 == 11 || n / 5 == 111 || n / 5 == 1111) {
                num = 5-1;
                sum += 10*num;

                if(n == 5) sum += 1;
                if(n == 55) sum += 3;
                if(n == 555) sum += 6;
                if(n == 5555) sum += 10;

               }
               else if(n / 6 == 1 || n / 6 == 11 || n / 6 == 111 || n / 6 == 1111) {
                num = 6-1;
                sum += 10*num;

                if(n == 6) sum += 1;
                if(n == 66) sum += 3;
                if(n == 666) sum += 6;
                if(n == 6666) sum += 10;

               }

               else if(n / 7 == 1 || n / 7 == 11 || n / 7 == 111 || n / 7 == 1111) {
                num = 7-1;
                sum += 10*num;

                if(n == 7) sum += 1;
                if(n == 77) sum += 3;
                if(n == 777) sum += 6;
                if(n == 7777) sum += 10;

               }

               else if(n / 8 == 1 || n / 8 == 11 || n / 8 == 111 || n / 8 == 1111) {
                num = 8-1;
                sum += 10*num;

                if(n == 8) sum += 1;
                if(n == 88) sum += 3;
                if(n == 888) sum += 6;
                if(n == 8888) sum += 10;

               }

               else if(n / 9 == 1 || n / 9 == 11 || n / 9 == 111 || n / 9 == 1111) {
                num = 9-1;
                sum += 10*num;

                if(n == 9) sum += 1;
                if(n == 99) sum += 3;
                if(n == 999) sum += 6;
                if(n == 9999) sum += 10;

               }

               System.out.println(sum);
        }

    }

    }

import java.util.Scanner;

public class A {
	public static void main(String... g) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		while (t-->0) {
			int x = scanner.nextInt();
			int r = 0;
			for (int i = 1; i <= x; i++) {
				boolean flag = true;
				String s = Integer.toString(i);
				char c = s.charAt(0);
				for (int j = 1; j < s.length(); j++) {
					if (s.charAt(j) != c) {
						flag = false;
						break;
					}
				}
				if (flag) {
					System.out.print(s+",");
					r += s.length();
				}
			}
			System.out.println(r);
		}
	}

}

import java.util.Scanner;

/**
 *
 * @author Eng.Razan
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */

/**
 *
 * @author Eng.Razan
 */
 static public class NewClass {

    Scanner s = new Scanner(System.in);
   // int cc = s.nextInt();
   // int x = s.nextInt();
   // int y = s.nextInt();
   // int maxx = s.nextInt();
    int i, j;
    int max ;
int maxx;
    int count = 0;

    void ss() {
       // for (int j = 0; j <= cc; j++) {
//System.out.println("nmhbjb");
            int x = s.nextInt();
          //  int y = s.nextInt();
          //  int maxx = s.nextInt();
            for (i = 0; i < x; i++) {
               String y = s.next();
max=Character.getNumericValue(y.charAt(0)) ;
maxx=(max-1)*10;
if(y.length()==1){maxx=1;}
if(y.length()==2){
    maxx=maxx+3;

}
if(y.length()==3){
    maxx=maxx+6;

}
if(y.length()==4){
    maxx=maxx+10;

} System.out.println(maxx);

            }
         //   System.out.println(maxx);
        }

   // }
}
    public static void main(String[] args) {
     //   System.out.println("roooz");
        // TODO code application logic here
        NewClass n=new NewClass();
        n.ss();
    }

}

import javax.swing.text.html.HTMLDocument;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

public class Main {

    public static void main(String[] args){
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for(int i=0;i<t;i++) {
                String str = br.readLine();
                int n = str.length();
                int p =Integer.parseInt(String.valueOf(str.charAt(0)));
                if(n==1){
                    out.println(1);
                }else if(n==2){
                    out.println(p*2);
                }else if(n==3){
                    out.println(p*6);
                }else if(n==4){
                    out.println(p*10);
                }
            }

            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }
    }
    static void swap(int[] arr,int i,int j){
        int temp = arr[i-1];
        arr[i-1] = arr[j-1];
        arr[j-1] = temp;
    }

    static int diff(String s1,String s2){
        int c=0;
        for(int i=0;i<s1.length();i++){
            if(s1.charAt(i)!=s2.charAt(i)){
                c++;
            }
        }
        return c;
    }
    static boolean isPal(String s){
        StringBuilder str=new StringBuilder(s);
        str=str.reverse();
        String ss=String.valueOf(str);
        if (ss.equals(s)) {
            return true;
        }
        return false;
    }
    static int mod(int a,int b){
        if (a>b){
            return a-b;
        }
        return b-a;
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static int lcm(int a,int b){
        long c=a*((long)b);
        return (int)(c/hcf(a,b));
    }
    static int hcf(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b)
            return hcf(a%b,b);

        return hcf(a,b%a);
    }

    static int modInverse(int x,int m){
        return power(x,m-2,m);
    }
    static int power(int x, int y, int m)
    {
        if (y == 0)
            return 1;

        long p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        return (int)((y%2==0)? p : (x*p)%m);
    }
    static class pair{
        int a,b;
        public pair(int a,int b){
            this.a=a;
            this.b=b;
        }
    }
}

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.lang.String.format;

public class Solution {

    private static ByteArrayOutputStream interceptedStream = new ByteArrayOutputStream();
    private static PrintStream systemOut = System.out;
    private static InputReader in  = new InputReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {

        String testFile = "NewRound/src/test/%s.txt";
        String testAns  = "NewRound/src/test/%sa.txt";

        for (int k = 1; k <= 0; k++) {

            enableTestFromFile(format(testFile, k));
            solve();

            long[] ans = getResultsFromInterceptedStreamAsLogArray();
            Assert.assertEquals(ans, $.readFileAsLong(format(testAns , k)));

            out.flush();
        }

        int tc = in.nextInt();

        for (int i = 0; i < tc; i++) {
            solve();
        }

        out.flush();
        out.close();
    }

    static void solve() {

        int x = in.nextInt();

        int count = 0;

        for (int i = 1; i <= 9; i++) {
            int k = 1;
            for (int j = i; j <= x; j = 10 * j + i) { // 6 * 7 + 3 + 3
//                System.out.println(j + " " + k);
                count += k;
                k++;
            }
        }

        out.println(count);

    }

    private static void enableTestFromFile(String fileName) throws IOException {
        System.setOut(new PrintStream(interceptedStream));
        out = new PrintWriter(System.out);
        in = new InputReader(new File(fileName));
    }

    private static long[] getResultsFromInterceptedStreamAsLogArray() {
        String[] stringArray = getResultsFromInterceptedStreamAsStringArray();
        return $.arrayStringToLong(stringArray);
    }

    private static String[] getResultsFromInterceptedStreamAsStringArray() {
        out.flush();
        String[] stringArray = interceptedStream.toString().split("\r\n");

        interceptedStream.reset();
        System.setOut(systemOut);
        out = new PrintWriter(System.out);

        return stringArray;
    }

    /**
     * Assert method for testing.
     */
    private static class Assert {

        static void assertEquals(int actual, int expected) {
            if (actual != expected) {
                throw new RuntimeException("\n" + actual + " != "  + expected);
            }
        }

        static void assertEquals(long actual, long expected) {
            if (actual != expected) {
                throw new RuntimeException("\n" + actual + " != "  + expected);
            }
        }

        static void assertEquals(int[] actual, int[] expected) {
            if (!Arrays.equals(actual, expected)) {
                throw new RuntimeException("\n" + Arrays.toString(actual)
                        + "\n" + Arrays.toString(expected));
            }
        }

        static void assertEquals(long[] actual, long[] expected) {
            if (!Arrays.equals(actual, expected)) {
                throw new RuntimeException("\n" + Arrays.toString(actual)
                        + "\n" + Arrays.toString(expected));
            }
        }
    }

    /**
     * Class for read input.
     */
    private static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        /**
         * Read from file.
         */
        InputReader(File file) throws FileNotFoundException {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)), 32768);
            tokenizer = null;
        }

        /**
         * Read from stream.
         */
        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        boolean hasNext() {
            try {
                return reader.ready();
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }

        String next() {

            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String[] readArrayString(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }

        int[] readArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] readArrayLong(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {

                array[i] = nextLong();
            }
            return array;
        }

        long[][] readDoubleArrayLong(int n) {
            long[][] array = new long[n][2];
            for (int i = 0; i < n; i++) {

                array[i][0] = nextLong();
                array[i][1] = nextLong();
            }
            return array;
        }

        String[][] readMatrixString(int n) {
            String[][] matrix = new String[n][n];

            for (int i = 0; i < n; i++) {
                matrix[i] = readArrayString(n);
            }
            return matrix;
        }
    }

    /**
     * Util class with different util methods.
     */
    private static class $ {

        static int[] ints(int... args) {
            return args;
        }

        static long[] longs(long... args) {
            return args;
        }

        static String[] strings(String... args) {
            return args;
        }

        static long[] arrayStringToLong(String[] stringArray) {
            long[] longArray = new long[stringArray.length];

            for (int i = 0; i < stringArray.length; i++) {
                longArray[i] = Long.parseLong(stringArray[i].trim());
            }
            return longArray;
        }

        static int[] arrayStringToInt(String[] stringArray) {
            int[] intArray = new int[stringArray.length];

            for (int i = 0; i < stringArray.length; i++) {
                intArray[i] = Integer.parseInt(stringArray[i].trim());
            }
            return intArray;
        }

        static long GCD(long a, long b) {
            return b == 0 ? a : GCD(b, a % b);
        }

        static boolean isPrime(long n) {
            if (n == 1) return false;

            long limit = (long) Math.sqrt(n);
            for (long i = 2; i <= limit; i++) {
                if (n % i == 0) return false;
            }
            return true;
        }

        static String[] readFile(String fileName) {
            List<String> list = new ArrayList<>();

            try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
                list = stream.collect(Collectors.toList());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return list.toArray(new String[0]);
        }

        static long[] readFileAsLong(String fileName) {
            return arrayStringToLong(readFile(fileName));
        }

        static int[] readFileAsInt(String fileName) {
            return arrayStringToInt(readFile(fileName));
        }
    }
}