LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of Eratosthenes
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

Barcode Check

Super EasyProblem #17
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

The store list is already sorted - use that.

A store sells many kinds of products and their barcodes are known, given as a sorted list. A manufacturer delivers a list of barcodes of its own products, in no particular order. Your task is to determine how many of the manufacturer's products are already sold in the store.

Input

The first line contains a single integer t - the number of testcases.

  • The first line of each testcase contains two integers n and q - the number of products in the store and the number of the manufacturer's products.
  • The next line contains n integers in increasing order - the barcodes of the products in the store.
  • The next line contains q integers - the barcodes of the manufacturer's products.

Output

For every testcase print a single line with the number of the manufacturer's barcodes that appear on the store's list.

Example

Input
1
5 5
1 3 5 6 7
2 3 4 5 8
Output
2

Of the manufacturer's barcodes, only 3 and 5 appear on the store's list.

Constraints

1≤t≤1000
1≤n,q≤2⋅105
1≤ai​≤109
Both the sum of n and the sum of q over all testcases are at most 2⋅105.


This problem was adapted, with permission, from Provera bar-kodova, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit