All Submissions


Gourav Ghosh is also known as 'Kiddo' because of his childish behaviour. You may think that this is cute but sometime it is just irritating. During Pantheon he was assigned a simple task to distribute tags to students according to a list. But as soon as he got the tags, he started running (in his own unique style) and distributed tags randomly to anyone listed, failing to notice that names were already written on the tag.

Now, these students were denied entry to ground at night as names on their tag didn't match with their ID card. Gourav noticed that all these students are standing next to one another and so he asked them to keep swaping tags with their neighbours until every one gets their tag. Imagine the mess this method will create. However, these students were smart and so they made swaps in the optimal way. Still, I am worried that the number of swaps may very large and so I need your help. I will provide you with the sequence in which students are standing and the tag they have. For simplicity I have assigned an integer to each student. Your job is to tell me the number of swaps required.

First line of input will contain the number of test cases T.
First line of each test case will number of students N.
Second and third line contains N integers, p[i] and t[i], denoting sequence in which each student is standing and the tag they have respectively.

Constrains

T <= 10
N <= 100000
1 <= p[i], t[i] <= 100000


Sample Input

3
5
1 2 3 4 5
5 1 2 3 4
5
2 5 3 1 4
5 2 3 4 1
5
1 2 3 4 5
5 2 3 4 1


Sample Output

4
2
7


Problem Setter : Pushkar Anand

Languages: Brain,C,C++,Java,C#,JavaScript,Pascal,Perl,PHP,Python,Ruby,Text

Time Limit: 1 Second(s)
Score: 100 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

No Clarifications.

Contest

Mode Judge

Passive

Online

Overall Rankings

RankNameScore
1xyz0
2Ams0
3TIP0
4team420
5xyzz0
6asdasdasd0
7abcd0
8khankhan0
9Gabriel0
10gigel0