CF856C.Eleventh Birthday

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

It is Borya's eleventh birthday, and he has got a great present: nn cards with numbers. The ii -th card has the number aia_{i} written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 11 , 3131 , and 1212 , and he puts them in a row in this order, he would get a number 1311213112 .

He is only 11, but he already knows that there are n!n! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112=1192×1113112=1192×11 , but if he puts the cards in the following order: 3131 , 11 , 1212 , he would get a number 3111231112 , it is not divisible by 1111 , so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there.

Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways.

Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353998244353 .

输入格式

Input data contains multiple test cases. The first line of the input data contains an integer tt — the number of test cases ( 1<=t<=1001<=t<=100 ). The descriptions of test cases follow.

Each test is described by two lines.

The first line contains an integer nn ( 1<=n<=20001<=n<=2000 ) — the number of cards in Borya's present.

The second line contains nn integers aia_{i} ( 1<=ai<=1091<=a_{i}<=10^{9} ) — numbers written on the cards.

It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 20002000 .

输出格式

For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353998244353 .

输入输出样例

  • 输入#1

    4
    2
    1 1
    3
    1 31 12
    3
    12345 67 84
    9
    1 2 3 4 5 6 7 8 9
    

    输出#1

    2
    2
    2
    31680
    
首页