QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#17939. !!Beware of Chocolate Addiction!!

Estadísticas

Coco's chocolate shop is famous for its sweet chocolates. Because of this, Coco wants to put the following warning sign in front of the shop:

!!Beware of Chocolate Addiction!!

While looking closely at this phrase, Coco realized that if you erase the sentence between the exclamation marks and put a number in its place, it becomes a kind of mathematical expression. Let's calculate this expression.

The expression to be calculated in this problem consists of one integer and zero or more exclamation marks. The integer is either $0$ or $1$, and exclamation marks can appear before or after the integer. The rules for calculating this expression are as follows:

  • $n!$ is the factorial of $n$. It is defined as $0! = 1$ and $1! = 1$.
  • $!n$ is the logical NOT of $n$. It is defined as $!0 = 1$ and $!1 = 0$.
  • If factorials or logical NOTs are nested, they are calculated as many times as they are nested. If both are used, such as in $!n!$, the factorial is calculated first. For example, $!!n!! = !(!((n!)!))$.

Input

The first line contains the number of expressions $T$. $(1 \le T \le 1\,000)$

From the second line, $T$ expressions are given, one per line. Each expression is in the form of $a$ exclamation marks, an integer $n$, and $b$ exclamation marks, concatenated without spaces. $(0 \le a, b \le 30;$ $0 \le n \le 1)$

Output

Print the result of each expression calculation, one per line.

Examples

Input 1

6
0!
1!
!0
!1
!!0!!
!!1!!

Output 1

1
1
1
0
1
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.