YODANESS - Yodaness Level


Yoda is the wisest, and perhaps the most powerful Jedi of his time. Yoda is a mysterious figure and he has many oddities. One of them is that Yoda often changes the order of words in the sentence. For example, one of such phrases is "Or I will help you not." Let's call the yodaness level of any statement the number of pairs of words that changed their order, as to the order in which they were supposed to go in a normal statement. Write a program that determines the yodaness level of different statement of Yoda.

 

Input

The first line of input contains the number t - the number of tests. Next comes the description of t tests. Each test consists of three rows. The first line of the test contains an integer n - number of words in the statement. The next line contains n words separated by spaces - the statement as Yoda says it. The next line is n words separated by spaces - the same statement as it should be said normally. All the words in the statement are different and consist of small latin letters.

Constraints

1 <= t <= 10
1 <= n <= 30000
the length of each word does not exceed 20 characters

Output

For each test print the yodaness level of the statement.

Example

Input:
2
6
in the force strong you are
you are strong in the force
6
or i will help you not
or i will not help you

Output:
11
2

hide comments
babur: 2017-05-25 06:38:17

Map + invinct

shahzada: 2017-03-21 19:17:50

very easy :)

aditya1997: 2016-08-31 13:46:22

an array of strings + BIT + maps = AC .........XD

rraj001: 2016-08-25 06:00:28

mergesort+stl :)AC in one go!

tushar96: 2016-08-12 12:37:32

maps + mergesort =AC :)

fly_sky12: 2016-07-14 15:10:23

a good question for maps STL.

siddiboy: 2016-07-07 20:34:54

great question!!!
learnt to use map in a better way

citransvostok: 2016-06-29 14:57:53

simple divide and conquer 0.21 AC

adi_1996: 2016-06-25 08:34:15

maps + INVCNT :)

mkfeuhrer: 2016-06-22 13:13:08

same as INVCNT !! just used map and printf/scanf AC :-)


Added by:Spooky
Date:2010-03-09
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Advancement Spring 2010, http://sevolymp.uuuq.com/