CF1703D.Double Strings

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

Double Strings

You are given nn strings s1,s2,,sns_1, s_2, \dots, s_n of length at most 8\mathbf{8}.

For each string sis_i, determine if there exist two strings sjs_j and sks_k such that si=sj+sks_i = s_j + s_k. That is, sis_i is the concatenation of sjs_j and sks_k. Note that jj can be equal to kk.

Recall that the concatenation of strings ss and tt is s+t=s1s2spt1t2tqs + t = s_1 s_2 \dots s_p t_1 t_2 \dots t_q, where pp and qq are the lengths of strings ss and tt respectively. For example, concatenation of "code" and "forces" is "codeforces".

Input

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1n1051 \leq n \leq 10^5) — the number of strings.

Then nn lines follow, the ii-th of which contains non-empty string sis_i of length at most 8\mathbf{8}, consisting of lowercase English letters. Among the given nn strings, there may be equal (duplicates).

The sum of nn over all test cases doesn't exceed 10510^5.

Output

For each test case, output a binary string of length nn. The ii-th bit should be 1 if there exist two strings sjs_j and sks_k where si=sj+sks_i = s_j + s_k, and 0 otherwise. Note that jj can be equal to kk.

Note

In the first test case, we have the following:

  • s1=s2+s2s_1 = s_2 + s_2, since abab} = \texttt{ab} + \texttt{ab. Remember that jj can be equal to kk.
  • s2s_2 is not the concatenation of any two strings in the list.
  • s3=s2+s5s_3 = s_2 + s_5, since abc} = \texttt{ab} + \texttt{c.
  • s4s_4 is not the concatenation of any two strings in the list.
  • s5s_5 is not the concatenation of any two strings in the list.

Since only s1s_1 and s3s_3 satisfy the conditions, only the first and third bits in the answer should be 1, so the answer is 10100.

Samples

3
5
abab
ab
abc
abacb
c
3
x
xx
xxx
8
codeforc
es
codes
cod
forc
forces
e
code
10100
011
10100101

在线编程 IDE

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