(while(print(*([rec(f x a b c)(if(= x 0)0(+(/ #0=(mod x b)c)(*(f(- x #0#)(+ a 1)(* a b)b)10)))](read)3 2 1)10)))