QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 100

#8497. Accumulator

Estadísticas

A new digital device for storing information is being studied. Information on the device is stored as a sequence of cells, each of which is in one of two states, denoted by the symbols "+" and "-", and thus stores one bit of information.

We define a fragment as a group of adjacent cells with the same state, such that to its left there is either no cell or a cell in the opposite state, and to its right there is either no cell or a cell in the opposite state.

A write operation allows choosing any pair of adjacent fragments of different lengths and changing the state of all cells in the shorter fragment to the opposite, thereby merging two or three adjacent fragments into one.

You are required to write a program that, given an initial and a final sequence of cell states, determines whether the final sequence can be obtained from the initial sequence using a sequence of write operations.

Input

The first line of the input contains a positive integer $q$ — the number of test cases.

Each of the following $q$ lines contains $s_i, t_i$ — non-empty sequences of "+" and "-" symbols of equal length, separated by a single space. This line means that in test case $i$, it is required to obtain the final sequence $t_i$ from the initial sequence of cell states $s_i$.

Output

The output should contain $q$ lines, where the $i$-th line is "Yes" if the final sequence $t_i$ can be obtained from the initial sequence $s_i$, or "No" otherwise.

Examples

Input 1

3
++- +++
++-- ++++
++-+--+- ++++++++

Output 1

Yes
No
Yes

Input 2

3
++-+-- ++----
++-+-- +++---
-++- -++-

Output 2

Yes
No
Yes

Subtasks

Subtask Points Constraints Required Subtasks
1 20 $\sum s_i \leqslant 16$, $t_i$ consists of "+" symbols
2 30 $\sum s_i \leqslant 1000$, $t_i$ consists of "+" symbols 1
3 20 $\sum s_i \leqslant 10^6$, $t_i$ consists of "+" symbols 1, 2
4 20 $\sum s_i \leqslant 1000$ 1, 2
5 10 $\sum s_i \leqslant 10^6$ 1–4

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.