This page is still under construction.

Parts of this page are still being built. What you see may change.

Urdu orthography verification

Time limit1sMemory limit256 MB

Summary
Check whether each encoded Urdu letter uses the detached, initial, medial or final shape required by its position and the two special vowels.
Level

Easy2 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Urdu is written in the Nastaleeq or Naskh styles, from right to left and top to bottom. In these styles the shape of a letter depends on where that letter sits inside the word.

Every letter has a detached shape used on its own, plus up to three more shapes: initial, medial and final. Take the Urdu word for "picture", transliterated as tasviir. Read right to left, its letters are ta, s, vaow, cchoTi yay, ray. The first letter, ta, starts the word, so it takes its initial shape. The second letter, s, sits between two consonants, so it takes its medial shape, and the third letter, vaow, takes its medial shape for the same reason. The fourth letter, cchoTi yay, is preceded by vaow, one of the two special vowels of Urdu. alif and vaow are special because the letter right after them must be written in its initial shape. So cchoTi yay takes its initial shape even though it does not start the word. The last letter, ray, ends the word, so it takes its final shape.

Given a sequence of letters, each in some shape, decide whether the word is written correctly.

For this problem the 38 letters of the alphabet are numbered 11 through 3838. The first letter is 11, the second is 22, and the last is 3838. The four shapes are encoded as detached 00, initial 11, medial 22 and final 33. A letter in a given shape is written as a single value: multiply the letter number by 44 and add the shape code.

The special vowels are letter numbers 11 and 3333, whatever shape those two letters themselves are written in. In a word of length MM, the shape required for the ii-th letter (1≤i≤M1 \le i \le M) comes from the first matching condition below, read top to bottom.

  • If M=1M = 1, the letter is detached.
  • If i=Mi = M and the preceding letter is a special vowel, the letter is detached.
  • If i=Mi = M and the preceding letter is not a special vowel, the letter is final.
  • If i=1i = 1, or the preceding letter is a special vowel, the letter is initial.
  • Otherwise the letter is medial.

The word is correct when every letter is written in the shape it requires.

Input

The first line holds the number of test cases NN (1≤N≤1001 \le N \le 100). Each of the next NN lines holds a word length MM (1≤M≤201 \le M \le 20) followed by the MM encoded values of that word, separated by spaces. An encoded value is built as described above, so it is between 44 and 155155.

Output

For each test case print one line. Print Case #n: Yes if the word uses the required shapes, and Case #n: No otherwise. Here nn is the test case number, counting from 11.

Examples2

  1. Example 1

    Input
    3
    5 17 82 134 150 59
    3 13 6 114
    4 13 6 121 115
    
    Expected output
    Case #1: No
    Case #2: No
    Case #3: Yes
    
  2. Example 2

    Input
    5
    1 4
    1 5
    1 155
    1 152
    1 82
    
    Expected output
    Case #1: Yes
    Case #2: No
    Case #3: No
    Case #4: Yes
    Case #5: No