本站作为LDUOnlineJudge的测试版本进行演示,官方网站请访问http://icpc.ldu.edu.cn
[Hidden]

1303. B. Simplified Keyboard


Description

Consider a simplified keyboard consisting of the 26 lowercase letters as illustrated below:

We define the neighbors of a key (letter) as all the letters adjacent to it. For example, the neighbors of ‘a’ are {b, k, j}, neighbors of ‘b’ are {a, c, l, k, j}, neighbors of ‘n’ are {d, e, f, o, x, w, v, m}, and neighbors of ‘z’ are {p, q, r, y}.


The Problem:
Given two words consisting of lowercase letters only, you are to determine which of the following three cases applies to them:
            1. identical: this is when the two words are of the same length and they match letter-by-letter. For example, “cool” and “cool” are identical, “cool” and “col” are not, and “cool” and “colo” are not.
            2. similar: this is when the two words are of the same length, they are not identical words, and each corresponding two letters either match or are neighbors. For example, “aaaaa” and “abkja” are similar, “moon” and “done” are similar, “knq” and “bxz” are similar, but “ab” and “cb” are not (because of ‘a’ in the first word and the corresponding ‘c’ in the second word).
            3. different: this is when neither of the above two cases applies to the two words, i.e., they are not identical and they are not similar. For example, “ab” and “abc” are different, “ab” and “az” are different, and “az” and “za” are different.

Input

The first input line contains a positive integer, n, indicating the number of test cases to process. Each of the following n input lines represents a test case, consisting of two words separated by one space. Each word consists of lowercase letters only and will be between 1 and 20 letters, inclusive.

Output

For each test case, output one line. That line should contain the digit (number) 1, 2, or 3, to indicate which of the above three cases applies to the two input words.

Samples

Input Copy
7
a k
a a
a z
cool cool
aaaaa abkja
ab abc
az za
Output
2
1
3
1
2
3
3

Source

UCF2017
Problem Information

Time Limit: 1000MS (C/C++,Others×2)
Memory Limit: 128MB (C/C++,Others×2)
Special Judge: No
AC/Submit: 1 / 1
Tags:
Contests involved

1034. UCF 2017
My history solutions

You didn't submit any solution!
Submit your solution

Login Register