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
mkfeuhrer: 2016-06-22 13:13:08

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

lynx_: 2016-06-18 09:30:32

BIT 0.22
MERGE_SORT_MODIFIED 0.22
:P

narutorocks: 2016-06-11 18:26:01

Easy one AC in one go solve INVCNT before you solve this

siddharth: 2016-04-29 13:14:45

I have solved INVCNT and i am using the same algo for this problem still it is giving me TLE
I am using STL+mergesort.
Please help

Edit
solved using maps+mergesort

Last edit: 2016-04-29 14:22:52
Safayet Islam Anonno: 2016-01-21 14:07:23

Thanks Rajat for your clarification. It helped.

Advitiya: 2015-10-20 22:48:29

STL+mergesort :'D AC

Mayank Garg: 2015-08-07 12:34:16

Just basic STL !! :D

BALMUKUND SINHA: 2015-07-24 22:15:43

100th question

Last edit: 2015-07-24 22:15:54
PRIBAN91: 2015-07-24 14:53:28

The problem statement should be bit more descriptive. Otherwise a good problem. Thanks Rajat.

r0bo_dart: 2015-06-25 12:34:20

maps + INVCNT :D


Added by:Spooky
Date:2010-03-09
Time limit:0.934s
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/