H. Game Design
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are a game designer working on a new video game, Outstandingly Captivating Platforming Challenge. The game consists of $$$n$$$ levels indexed $$$1 \ldots n$$$, which the player must complete in that order. In addition to the normal progression, the levels are also connected through $$$n$$$ one-way warp portals. A different team in your company has already completed the design of each level. They have placed one warp portal entrance and one warp portal exit in every level. Your task is to connect each entry portal to an exit portal on a different level such that each exit portal is also connected to only one entry portal.

However, there is an additional restriction: the player must not be able to skip ahead in the game. That is, the player must not be able to enter a portal, exit at a portal on a later level, and keep playing on that later level. In order to make this possible, the level designers have placed some exit portals in isolated locations from which the rest of the level is not accessible. That is: if an entry portal on level $$$u$$$ leads to an exit portal on some level $$$v \gt u$$$, then the exit portal on level $$$v$$$ must be in an isolated location.

You have already written a program to examine all allowed ways to connect each entry portal to an exit portal, in order to measure the predicted audience engagement. That program has been running for a while now, your boss is getting angry, and you want to know how long this program will take. Thus, calculate the number of allowed ways to connect each entry portal to an exit portal. Print the answer modulo $$$998\,244\,353$$$.

Input

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. $$$t$$$ test cases follow.

Each test case consists of a binary string $$$s$$$ of length $$$n$$$ ($$$2 \le n \le 5000$$$). The $$$i$$$-th character of $$$s$$$ is 1 if the exit portal on level $$$i$$$ is at an isolated location, and 0 otherwise.

It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$5000$$$.

Output

For each test case, print the answer modulo $$$998\,244\,353$$$ on a separate line.

Example
Input
4
0101
1010010010001010
11111
10100100011000010010101001001001
Output
3
0
44
393298077
Note

In the first example test, the valid configurations are $$$[2, 1, 4, 3]$$$, $$$[2, 4, 1, 3]$$$ and $$$[4, 1, 2, 3]$$$, where the $$$i$$$-th position in the array is the location of the exit portal connected to the entry portal on the $$$i$$$-th level.

In the second example test, there is no entry portal that can be connected to the exit portal on the last level.