#C4283. Organize Books

    ID: 47804 Type: Default 1000ms 256MiB

Organize Books

Organize Books

Given a stack of books, organize them into their designated shelves with the minimum number of moves.

Each book has a unique ID. You are provided with the order of the books in the stack (from bottom to top) and a list denoting the designated shelf for each book. Although the shelf assignment is given for each book, each move consists of taking a single book from the stack. Thus, the minimum number of moves required to organize the books is simply equal to the total number of books.

Your task is to compute this number for each test case.

inputFormat

The first line contains an integer T, the number of test cases.

Each test case begins with a line containing two integers N and M where:

  • N is the number of shelves (this value is provided but not used in the computation), and
  • M is the number of books.

The next line contains M integers representing the book IDs in the order they appear in the stack (from bottom to top).

The following line contains M integers representing the shelf assignments for the books. The i-th number corresponds to the shelf for the book with ID i+1.

outputFormat

For each test case, output a single line containing one integer: the minimum number of moves required to organize the books.

## sample
2
3 5
5 4 3 2 1
3 1 2 3 1
2 3
1 2 3
1 2 1
5

3

</p>