using System.Collections.Generic; using System; public class hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var t = int.Parse(line[0]); var b = int.Parse(line[1]); while (t-- > 0) { var n = int.Parse(Console.ReadLine().Trim()); var ans = new List(); while (true) { var mod = n % b; n /= b; if (mod < 0) { n++; mod += (-b); } ans.Add(mod); if (n == 0) break; } ans.Reverse(); Console.WriteLine(string.Join("", ans)); } } }