This page is still under construction.

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

Jaccard Similarity Threshold

Interview

Time limit1sMemory limit512 MB

Summary
Given two small sets of digits, decide whether their Jaccard similarity is greater than 0.5.
Level

Easy2 of 10

Topics
Implementation, Math
Solved
No attempts yet

Problem

The Jaccard similarity coefficient measures how similar two sets are. For two sets AA and BB, the coefficient J(A,B)J(A, B) is the size of the intersection divided by the size of the union, that is J(A,B)=∣A∩B∣∣A∪B∣J(A, B) = \frac{|A \cap B|}{|A \cup B|}. For example, if A={1,3,7,8}A = \{1, 3, 7, 8\} and B={1,7,9}B = \{1, 7, 9\}, then J(A,B)=∣{1,7}∣∣{1,3,7,8,9}∣=25J(A, B) = \frac{|\{1, 7\}|}{|\{1, 3, 7, 8, 9\}|} = \frac{2}{5}.

Every element of a set is an integer between 0 and 9, and no set holds more than 10 elements. Given two sets AA and BB, compute J(A,B)J(A, B) and print 1 when J(A,B)>0.5J(A, B) > 0.5, or 0 when J(A,B)≤0.5J(A, B) \le 0.5.

Input

The first line contains the number of test cases TT (1≤T≤251 \le T \le 25).

Each test case consists of three lines. The first line contains mm and nn, the number of elements of AA and the number of elements of BB (1≤m,n≤101 \le m, n \le 10). The second line contains the mm elements of AA and the third line contains the nn elements of BB, separated by spaces. Every element is an integer between 0 and 9, and the same value never appears twice inside one set.

Output

For each test case, print 1 if J(A,B)>0.5J(A, B) > 0.5 and 0 if J(A,B)≤0.5J(A, B) \le 0.5, one answer per line.

Examples4

  1. Example 1

    Input
    3
    5 6
    0 2 3 5 6
    1 2 4 6 7 9
    3 2
    1 4 6
    4 6
    7 7
    0 1 3 4 6 8 9
    0 1 2 3 4 6 7
    
    Expected output
    0
    1
    1
    
  2. Example 2

    Input
    1
    1 1
    5
    5
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    1 1
    0
    9
    
    Expected output
    0
    
  4. Example 4

    Input
    2
    3 3
    1 2 3
    1 2 4
    2 4
    1 2
    1 2 3 4
    
    Expected output
    0
    0