아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Soccer Teams

시간 제한5초메모리 제한1024 MB

요약
1부터 9까지의 개수가 주어질 때, 0을 원하는 만큼 덧붙여 만들 수 있는 가장 작은 11의 배수의 자릿수를 구한다.
난이도

보통10점 중 7점

유형
정수론, 그리디, 수학, 조합론
정답자
아직 제출이 없습니다

문제

My kid's favorite subject is math, as you know by now. He is learning division now, and his teacher has taught him about even numbers being divisible by 2, numbers whose digits add up to a multiple of 3 being exactly divisible by 3 etc.

He was familiar with division by 11 during selection for soccer teams on his playground, and was wondering whether there was any easy rule to see if a number was divisible by 11. For example, he wondered, if he arranged a number of digits 0-9 in a row to form a number, which ones would be divisible by 11?

He decided to start off with d[1] 1's, d[2] 2's ..., d[9] 9's, and seeing what is the minimum multiple of 11 that he could get by using all these digits, together with any number of 0's. Please help him figure out how many digits there are in this minimum multiple.

입력

The first line will contain the number of test cases T. T lines follow one corresponding to each test case. Each line has 9 integers d[1],...,d[9].

출력

Output T lines one corresponding to each test case. The ith line should contain the required answer for the corresponding test case. If he will not be able to form a multiple of 11 in this way, print -1.

제한

  • 1 ≤ T ≤ 100
  • 1 ≤ d[1] + ... + d[9] ≤ 100

힌트

For the first case, the number 11 can be formed which has 2 digits.

For the second case, number 209 can be formed which is divisible by 11 and has 3 digits.

예제1

  1. 예제 1

    입력
    2
    2 0 0 0 0 0 0 0 0
    0 1 0 0 0 0 0 0 1
    
    예상 출력
    2
    3