This page is still under construction.

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

Hamming Distance

Interview

Time limit1sMemory limit256 MB

Summary
Read two n-dimensional integer vectors and count the positions where their entries differ.
Level

Easy1 of 10

Topics
Implementation, Array
Solved
No attempts yet

Problem

The Hamming distance dH(v⃗,u⃗)d_H(\vec{v}, \vec{u}) between two nn-dimensional vectors v⃗=(v1,…,vn)\vec{v} = (v_1, \ldots, v_n) and u⃗=(u1,…,un)\vec{u} = (u_1, \ldots, u_n) is the number of positions at which the corresponding entries differ.

dH(v⃗,u⃗)=∣{ i:vi≠ui,  i∈{1,…,n} }∣d_H(\vec{v}, \vec{u}) = |\{\, i : v_i \neq u_i,\; i \in \{1, \ldots, n\} \,\}|

For example, the Hamming distance between (1,2,3,4,5)(1, 2, 3, 4, 5) and (1,0,0,4,5)(1, 0, 0, 4, 5) is 22. The two vectors differ only at the second position and the third position.

Write a program that computes the Hamming distance between two nn-dimensional vectors.

Input

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

Each test case consists of three lines. The first line contains the dimension nn of the vectors. (0<n≤500 < n \le 50) The second line contains v1,…,vnv_1, \ldots, v_n and the third line contains u1,…,unu_1, \ldots, u_n, separated by spaces. Every entry is an integer between 00 and 9999, inclusive.

Output

For each test case, print the Hamming distance between (v1,…,vn)(v_1, \ldots, v_n) and (u1,…,un)(u_1, \ldots, u_n), one per line.

Examples1

  1. Example 1

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