fun main(){ val t = readLine()!!.toInt() for (tests in 0..t - 1) { val M = readLine()!!.toLong() var A = readLine()!!.split(' ').map { it.toInt() }.toMutableList() var ANS=0.toLong() var count=9 for (i in 0..8){ while (A[i]>0){ ANS+=(Math.pow(10.0,count.toDouble())).toLong()*(i+1).toLong() count+=1 A[i]=A[i]-1 } } ANS+=M-ANS%M println(ANS) } }