Turn Off The Light

각 시작 위치마다 모든 전등을 끄는 최소 이동 횟수를 구한 뒤, 모든 답의 가중합을 10^9+7로 나눈 나머지를 출력한다.

어려움8그리디누적 합구현수학아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

There are nn lights aligned in a row. These lights are numbered 11 to nn from left to right. Initially some of the lights are turned on. Chiaki would like to turn off all the lights.

Chiaki starts from the pp-th light. Each time she can go left or right (i.e. if Chiaki is at xx, then she can go to x1x-1 or x+1x+1) and then press the switch of the light in that position (i.e. if the light is turned on before, it will be turned off and vise versa).

For each p=1,2,,np=1,2,\dots,n, Chiaki would like to know the minimum steps needed to turn off all the lights.

입력

There are multiple test cases. The first line of input is an integer TT indicates the number of test cases. For each test case:

The first line contains an integer nn (2n1062 \le n \le 10^6) -- the number of lights.

The second line contains a binary string ss where s_i=1s\_i=1 means the ii-th light is turned on and s_i=0s\_i=0 means ii-th light is turned off.

It is guaranteed that the sum of all nn does not exceed 10710^7.

출력

For each test cases, output (_i=1si×z_i)mod(109+7)(\sum\limits\_{i=1}^{|s|} i \times z\_i) \bmod (10^9+7), where z_iz\_i is the number of step needed when Chikai starts at the ii-th light.