CF1861B.Two Binary Strings

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Two Binary Strings

You are given two strings aa and bb of equal length, consisting of only characters 0 and/or 1; both strings start with character 0 and end with character 1.

You can perform the following operation any number of times (possibly zero):

  • choose one of the strings and two equal characters in it; then turn all characters between them into those characters.

Formally, you choose one of these two strings (let the chosen string be ss), then pick two integers ll and rr such that 1l<rs1 \le l \lt r \le |s| and sl=srs_l = s_r, then replace every character sis_i such that l<i<rl \lt i \lt r with sls_l.

For example, if the chosen string is 010101, you can transform it into one of the following strings by applying one operation:

  • 000101 if you choose l=1l = 1 and r=3r = 3;
  • 000001 if you choose l=1l = 1 and r=5r = 5;
  • 010001 if you choose l=3l = 3 and r=5r = 5;
  • 010111 if you choose l=4l = 4 and r=6r = 6;
  • 011111 if you choose l=2l = 2 and r=6r = 6;
  • 011101 if you choose l=2l = 2 and r=4r = 4.

You have to determine if it's possible to make the given strings equal by applying this operation any number of times.

Input

The first line contains a single integer tt (1t20001 \le t \le 2000)  — the number of test cases.

Each test case consists of two lines:

  • the first line contains the string aa (2a50002 \le |a| \le 5000), consisting of only characters 0 and/or 1.
  • the second line contains the string bb (2b50002 \le |b| \le 5000), consisting of only characters 0 and/or 1.

Additional constraints on the input:

  • in each test case, a=b|a| = |b| (the strings have equal length);
  • in each test case, both strings start with 0 and end with 1;
  • the total length of all strings aa in all test cases does not exceed 50005000.

Output

For each test case, print YES if it is possible to make the strings equal. Otherwise, print NO. You can print each letter in any register.

Note

In the first test case, we can perform the following operations:

  1. choose the string aa, l=2l = 2, r=4r = 4; after this operation, aa is 01110001, bb is 01110101;
  2. choose the string bb, l=5l = 5, r=7r = 7; after this operation, aa is 01110001, bb is 01110001.

In the second test case, the strings are already equal.

In the third test case, we can perform the following operations:

  1. choose the string aa, l=4l = 4, r=6r = 6; after this operation, aa is 000111, bb is 010111;
  2. choose the string bb, l=1l = 1, r=3r = 3; after this operation, aa is 000111, bb is 000111;

In the fourth and fifth test cases, it's impossible to make the given strings equal.

Samples

7
01010001
01110101
01001
01001
000101
010111
00001
01111
011
001
001001
011011
010001
011011
YES
YES
YES
NO
NO
NO
YES

在线编程 IDE

建议全屏模式获得最佳体验