using System.Collections.Generic; using System; public class Hello { static void Main() { var T = int.Parse(Console.ReadLine().Trim()); while (T-- > 0) { var m = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(m, a); } } static void getAns(int m, int[] a) { var c = new List(); for (int i = 0; i < 9; i++) for (int j = 0; j < a[i]; j++) c.Add(i + 1); var t = long.Parse(string.Join("", c) + new string('9', 9)); var r = t % m; Console.WriteLine(t - r); } }