High School Programming League 2008/2009

Subset or Element

Problem code: HS08SE

Given two sets A and B decide which of the following cases is satisfied.

  1. A is an element and a subset of B;
  2. A is an element but not a subset of B;
  3. A is a subset but not an element of B;
  4. A is neither an element nor a subset of B.

Sets are given by the sequence of commas, curly brackets, and E (denoting the empty set) symbols. Length of the set description does not exceed 100000 characters.

Input

First t, the number of test cases. In the following 2t lines description of set pairs, each set in the separate line in the same format as presented in the examples below.

Output

For each pair of sets output one number coresponding to the case described above.

Example 1

Input:
2
A = {E}
B = {{E}}
A = {E}
B = {{{E}}}

Output:
2
4

Comment: In the above examples A is a set containing one element: an empty set. In the first example A is an element of B, which is a set containing one element: a set containing one element: an empty set. In the second example B is also a a set containing one element, but its element is not the A set but, a set containing A as an element.

Example 2

Input:
5
A = {E}
B = {E,{{E}}}
A = {E}
B = {E,{E}}
A = {{{E}}}
B = {{E,E},{E,{E}},{E}}
A = {{E,{E}}}
B = {{E,E},{E,{E}},{E}}
A = {E}
B = {{E},E}

Output:
3
1
4
3
1

Example 3

Input:
1
A = {{E},E,E,E}
B = {{E,E},E,E,E,E,E,{{{E,{{E,{E},{E,E},{{{E,{{E,E}},E}}}}}}}}}

Output:
3

Comment: Please note, that an element of a set might be listed multiple times, what does not mean, that the set contains more than one copy of that element.

Scoring

For solving this problem you will score 10 points.


Added by:Łukasz Kuszner
Date:2009-01-19
Time limit:1s-3s
Source limit:50000B
Languages:SED C99 strict C++ 4.0.0-8 C++ 4.3.2 TCL SCALA NEM PHP SCM guile LISP sbcl LISP clisp ERL TECS TEXT DOC PDF PS PERL 6 JS
Resource:Problem originally posted by Robert Janczewski
SPOJ System © 2008-2009 Sphere Research Labs. All Rights Reserved.