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

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/

hide comments
2015-04-02 10:59:48 Rajat (1307086)
had to modify the code of INVCNT.
Those that did not understand the cases:
"in the force strong you are"
following are the yodaness pairs:
in strong
in you
in are
the strong
the you
the are
force strong
force you
force are
strong you
strong are
so total=11
2014-10-07 23:41:42 Mitch Schwartz
@Akshay: It seems clear enough to me. Suppose word A comes before word B in the original sentence. If Yoda's version puts A after B, then that counts as one reversal. You are concerned with the total number of reversals.
2014-10-07 23:16:26 Akshay Vats
Very unclear what yodaness is

Last edit: 2015-01-31 20:34:56
2013-08-24 09:57:48 BLANKRK
nice problm !!
2011-03-09 15:18:38 [Retired] Fendy Kosnatha
is algo for solve this problem same as https://www.spoj.pl/problems/INVCNT/ ??
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.