Leet

No attempts yetTime limit2sMemory limit128 MB

Problem

Leet is a way of writing in which each letter of the alphabet is replaced by one or more other characters, used mostly online. For example, replacing A with 4, E with 3, and T with 7 turns the word "ATE" into "437". A single letter may also be replaced by a string longer than one character, such as writing M as |V|.

A letter can sometimes be written in leet in more than one way (for example, D could be [), |), or |>), which is what makes leet hard to read.

Given an original word written in lowercase letters and a word written in leet, write a program that decides whether the two words correspond to each other under all of the following rules.

  1. When a letter is converted to leet, its replacement string has length at most kk (given in the input); that is, the length is between 1 and kk.
  2. Each letter maps to exactly one leet string. So if the same letter appears several times in the original word, every occurrence must be replaced by the same string. For example, if D is set to [), then D cannot also be |> in the same check.
  3. Two different letters may map to the same leet string. For example, D and P may both become |>.
  4. A letter and its leet string do not need to look alike.

Input

The first line contains the number of test cases TT. Each test case consists of three lines.

  • The first line contains kk, the maximum length of the leet string for a single letter (1k31 \le k \le 3).
  • The second line contains the original word, made up only of lowercase letters a-z, with length between 1 and 15.
  • The third line contains the word written in leet. Its length is at least 1, and it consists of a-z, A-Z, 0-9 and the symbols @ \ / - = ^ | [ ] ( ) { } < >.

Output

For each test case, print 1 if the original word can be turned into the leet word under the rules, and 0 otherwise, each on its own line.